Overte C++ Documentation
OpenXrDisplayPlugin.h
1 //
2 // Overte OpenXR Plugin
3 //
4 // Copyright 2024 Lubosz Sarnecki
5 // Copyright 2024 Overte e.V.
6 //
7 // SPDX-License-Identifier: Apache-2.0
8 //
9 
10 #pragma once
11 
12 #include <graphics/Geometry.h>
13 #include <display-plugins/hmd/HmdDisplayPlugin.h>
14 
15 #include "OpenXrContext.h"
16 
17 class OpenXrDisplayPlugin : public HmdDisplayPlugin {
18 public:
19  OpenXrDisplayPlugin(std::shared_ptr<OpenXrContext> c);
20  bool isSupported() const override;
21  const QString getName() const override;
22  bool getSupportsAutoSwitch() override final { return true; }
23 
24  glm::mat4 getEyeProjection(Eye eye, const glm::mat4& baseProjection) const override;
25  glm::mat4 getCullingProjection(const glm::mat4& baseProjection) const override;
26 
27  void init() override;
28 
29  float getTargetFrameRate() const override;
30  bool hasAsyncReprojection() const override { return true; }
31 
32  void customizeContext() override;
33  void uncustomizeContext() override;
34 
35  void resetSensors() override;
36  bool beginFrameRender(uint32_t frameIndex) override;
37  void submitFrame(const gpu::FramePointer& newFrame) override;
38  void cycleDebugOutput() override { _lockCurrentTexture = !_lockCurrentTexture; }
39 
40  int getRequiredThreadCount() const override;
41 
42  QRectF getPlayAreaRect() override;
43 
44  virtual StencilMaskMode getStencilMaskMode() const override { return StencilMaskMode::MESH; }
45  virtual StencilMaskMeshOperator getStencilMaskMeshOperator() override;
46 
47  glm::mat4 getSensorResetMatrix() const { return glm::mat4(1.0f); }
48 
49 protected:
50  bool internalActivate() override;
51  void internalDeactivate() override;
52  void updatePresentPose() override;
53 
54  void compositeLayers() override;
55  void hmdPresent() override;
56  bool isHmdMounted() const override;
57  void postPreview() override;
58 
59 private:
60  std::vector<gpu::TexturePointer> _compositeSwapChain;
61 
62  XrViewState _lastViewState;
63 
64  std::shared_ptr<OpenXrContext> _context;
65 
66  uint32_t _viewCount = 0;
67  std::vector<XrCompositionLayerProjectionView> _projectionLayerViews;
68 
69  std::optional<std::vector<XrView>> _views;
70 
71  std::vector<XrViewConfigurationView> _viewConfigs;
72 
73  std::vector<XrSwapchain> _swapChains;
74  std::vector<uint32_t> _swapChainLengths;
75  std::vector<uint32_t> _swapChainIndices;
76  std::vector<std::vector<XrSwapchainImageOpenGLKHR>> _images;
77 
78  XrFrameState _lastFrameState;
79 
80  bool initViews();
81  bool initSwapChains();
82  bool initLayers();
83  bool endFrame();
84 
85  bool _haveFrameToSubmit = false;
86  std::mutex _haveFrameMutex;
87 };