| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef OSGXR_OPENXR_COMPOSITOR |
| 5 |
#define OSGXR_OPENXR_COMPOSITOR 1 |
| 6 |
|
| 7 |
#include "Session.h" |
| 8 |
#include "Space.h" |
| 9 |
#include "SwapchainGroup.h" |
| 10 |
|
| 11 |
#include <osg/Referenced> |
| 12 |
#include <osg/ref_ptr> |
| 13 |
|
| 14 |
namespace osgXR { |
| 15 |
|
| 16 |
namespace OpenXR { |
| 17 |
|
| 18 |
class DepthInfo; |
| 19 |
|
| 20 |
class CompositionLayer : public osg::Referenced |
| 21 |
{ |
| 22 |
public: |
| 23 |
|
| 24 |
CompositionLayer() : |
| 25 |
_layerFlags(0) |
| 26 |
{ |
| 27 |
} |
| 28 |
|
| 29 |
virtual ~CompositionLayer() |
| 30 |
{ |
| 31 |
} |
| 32 |
|
| 33 |
inline XrCompositionLayerFlags getLayerFlags() const |
| 34 |
{ |
| 35 |
return _layerFlags; |
| 36 |
} |
| 37 |
inline void setLayerFlags(XrCompositionLayerFlags layerFlags) |
| 38 |
{ |
| 39 |
_layerFlags = layerFlags; |
| 40 |
} |
| 41 |
|
| 42 |
inline Space *getSpace() const |
| 43 |
{ |
| 44 |
return _space; |
| 45 |
} |
| 46 |
inline void setSpace(Space *space) |
| 47 |
{ |
| 48 |
_space = space; |
| 49 |
} |
| 50 |
|
| 51 |
virtual const XrCompositionLayerBaseHeader *getXr() = 0; |
| 52 |
|
| 53 |
protected: |
| 54 |
|
| 55 |
XrCompositionLayerFlags _layerFlags; |
| 56 |
osg::ref_ptr<Space> _space; |
| 57 |
}; |
| 58 |
|
| 59 |
class CompositionLayerProjection : public CompositionLayer |
| 60 |
{ |
| 61 |
public: |
| 62 |
|
| 63 |
CompositionLayerProjection(unsigned int viewCount) |
| 64 |
{ |
| 65 |
_layer.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION; |
| 66 |
_layer.next = nullptr; |
| 67 |
_projViews.resize(viewCount); |
| 68 |
_depthInfos.resize(viewCount); |
| 69 |
} |
| 70 |
|
| 71 |
virtual ~CompositionLayerProjection() |
| 72 |
{ |
| 73 |
} |
| 74 |
|
| 75 |
void addView(osg::ref_ptr<Session::Frame> frame, uint32_t viewIndex, |
| 76 |
const SwapchainGroup::SubImage &subImage, |
| 77 |
const DepthInfo *depthInfo = nullptr); |
| 78 |
|
| 79 |
const XrCompositionLayerBaseHeader *getXr() override; |
| 80 |
|
| 81 |
protected: |
| 82 |
|
| 83 |
mutable XrCompositionLayerProjection _layer; |
| 84 |
std::vector<XrCompositionLayerProjectionView> _projViews; |
| 85 |
std::vector<XrCompositionLayerDepthInfoKHR> _depthInfos; |
| 86 |
}; |
| 87 |
|
| 88 |
class CompositionLayerQuad : public CompositionLayer |
| 89 |
{ |
| 90 |
public: |
| 91 |
|
| 92 |
CompositionLayerQuad() : |
| 93 |
_layer{ XR_TYPE_COMPOSITION_LAYER_QUAD } |
| 94 |
{ |
| 95 |
_layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH; |
| 96 |
_layer.subImage.swapchain = XR_NULL_HANDLE; |
| 97 |
_layer.pose.orientation = { 0.0f, 0.0f, 0.0f, 1.0f }; |
| 98 |
} |
| 99 |
|
| 100 |
virtual ~CompositionLayerQuad() |
| 101 |
{ |
| 102 |
} |
| 103 |
|
| 104 |
inline XrEyeVisibility getEyeVisibility() const |
| 105 |
{ |
| 106 |
return _layer.eyeVisibility; |
| 107 |
} |
| 108 |
inline void setEyeVisibility(XrEyeVisibility eyeVisibility) |
| 109 |
{ |
| 110 |
_layer.eyeVisibility = eyeVisibility; |
| 111 |
} |
| 112 |
|
| 113 |
void setSubImage(const SwapchainGroup::SubImage &subImage); |
| 114 |
|
| 115 |
inline osg::Quat getOrientation() const |
| 116 |
{ |
| 117 |
return osg::Quat(_layer.pose.orientation.x, |
| 118 |
_layer.pose.orientation.y, |
| 119 |
_layer.pose.orientation.z, |
| 120 |
_layer.pose.orientation.w); |
| 121 |
} |
| 122 |
inline void setOrientation(const osg::Quat &quat) |
| 123 |
{ |
| 124 |
_layer.pose.orientation.x = quat.x(); |
| 125 |
_layer.pose.orientation.y = quat.y(); |
| 126 |
_layer.pose.orientation.z = quat.z(); |
| 127 |
_layer.pose.orientation.w = quat.w(); |
| 128 |
} |
| 129 |
|
| 130 |
inline osg::Vec3f getPosition() const |
| 131 |
{ |
| 132 |
return osg::Vec3f(_layer.pose.position.x, |
| 133 |
_layer.pose.position.y, |
| 134 |
_layer.pose.position.z); |
| 135 |
} |
| 136 |
inline void setPosition(const osg::Vec3f &pos) |
| 137 |
{ |
| 138 |
_layer.pose.position.x = pos.x(); |
| 139 |
_layer.pose.position.y = pos.y(); |
| 140 |
_layer.pose.position.z = pos.z(); |
| 141 |
} |
| 142 |
|
| 143 |
inline osg::Vec2f getSize() const |
| 144 |
{ |
| 145 |
return osg::Vec2f(_layer.size.width, |
| 146 |
_layer.size.height); |
| 147 |
} |
| 148 |
inline void setSize(const osg::Vec2f &size) |
| 149 |
{ |
| 150 |
_layer.size.width = size.x(); |
| 151 |
_layer.size.height = size.y(); |
| 152 |
} |
| 153 |
|
| 154 |
const XrCompositionLayerBaseHeader *getXr() override; |
| 155 |
|
| 156 |
protected: |
| 157 |
|
| 158 |
mutable XrCompositionLayerQuad _layer; |
| 159 |
}; |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
#endif |