Plasma Engine  2.0
Loading...
Searching...
No Matches
OpenVRSingleton.h
1#pragma once
2
3#include <Core/Graphics/Camera.h>
4#include <Foundation/Configuration/Singleton.h>
5#include <GameEngine/Interfaces/VRInterface.h>
6#include <OpenVRPlugin/Basics.h>
7#include <RendererCore/Pipeline/Declarations.h>
8#include <RendererCore/Shader/ConstantBufferStorage.h>
9#include <RendererFoundation/Descriptors/Descriptors.h>
10#include <RendererFoundation/Resources/RenderTargetSetup.h>
11
14
15class PL_OPENVRPLUGIN_DLL plOpenVR : public plVRInterface
16{
17 PL_DECLARE_SINGLETON_OF_INTERFACE(plOpenVR, plVRInterface);
18
19public:
20 plOpenVR();
21
22 virtual bool IsHmdPresent() const override;
23
24 virtual bool Initialize() override;
25 virtual void Deinitialize() override;
26 virtual bool IsInitialized() const override;
27
28 virtual const plHMDInfo& GetHmdInfo() const override;
29 virtual void GetDeviceList(plHybridArray<plVRDeviceID, 64>& out_Devices) const override;
30 virtual plVRDeviceID GetDeviceIDByType(plVRDeviceType::Enum type) const override;
31 virtual const plVRDeviceState& GetDeviceState(plVRDeviceID uiDeviceID) const override;
32 virtual plEvent<const plVRDeviceEvent&>& DeviceEvents() override;
33
34 virtual plViewHandle CreateVRView(
35 const plRenderPipelineResourceHandle& hRenderPipeline, plCamera* pCamera, plGALMSAASampleCount::Enum msaaCount) override;
36 virtual plViewHandle GetVRView() const override;
37 virtual bool DestroyVRView() override;
38 virtual bool SupportsCompanionView() override;
39 virtual bool SetCompanionViewRenderTarget(plGALTextureHandle hRenderTarget) override;
40 virtual plGALTextureHandle GetCompanionViewRenderTarget() const override;
41
42private:
43 void GameApplicationEventHandler(const plGameApplicationExecutionEvent& e);
44 void GALDeviceEventHandler(const plGALDeviceEvent& e);
45 void OnBeginRender(plUInt64);
46
47 void ReadHMDInfo();
48 void OnDeviceActivated(plVRDeviceID uiDeviceID);
49 void OnDeviceDeactivated(plVRDeviceID uiDeviceID);
50
51 void UpdatePoses();
52 void UpdateHands();
53 void SetStageSpace(plVRStageSpace::Enum space);
54 void SetHMDCamera(plCamera* pCamera);
55 void UpdateCamera();
56
57 plMat4 GetHMDProjectionEye(vr::Hmd_Eye nEye, float fNear, float fFar) const;
58 plMat4 GetHMDEyePose(vr::Hmd_Eye nEye) const;
59 plString GetTrackedDeviceString(
60 vr::TrackedDeviceIndex_t unDevice, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError* peError = nullptr) const;
61
62 static plMat4 ConvertSteamVRMatrix(const vr::HmdMatrix34_t& matPose);
63 static plVec3 ConvertSteamVRVector(const vr::HmdVector3_t& vector);
64
65private:
66 bool m_bInitialized = false;
67
68 vr::IVRSystem* m_pHMD = nullptr;
69 vr::IVRRenderModels* m_pRenderModels = nullptr;
70
71 plHMDInfo m_Info;
72 plVRDeviceState m_DeviceState[vr::k_unMaxTrackedDeviceCount];
73 plInt8 m_iLeftControllerDeviceID = -1;
74 plInt8 m_iRightControllerDeviceID = -1;
76
77 plWorld* m_pWorld = nullptr;
78 plCamera* m_pCameraToSynchronize = nullptr;
79 plEnum<plVRStageSpace> m_StageSpace;
80
81 plCamera m_VRCamera;
82 plUInt32 m_uiSettingsModificationCounter = 0;
83 plViewHandle m_hView;
84 plGALRenderTagetSetup m_RenderTargetSetup;
86 plGALTextureHandle m_hColorRT;
87 plGALTextureHandle m_hDepthRT;
88
89 plGALTextureHandle m_hCompanionRenderTarget;
90 plConstantBufferStorageHandle m_hCompanionConstantBuffer;
91 plShaderResourceHandle m_hCompanionShader;
92};
93
94PL_DYNAMIC_PLUGIN_DECLARATION(PL_OPENVRPLUGIN_DLL, plOpenVRPlugin);
A camera class that stores the orientation and some basic camera settings.
Definition Camera.h:41
Definition ConstantBufferStorage.h:54
Definition Event.h:177
Definition RendererFoundationDLL.h:411
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition OpenVRSingleton.h:16
The plTypedResourceHandle controls access to an plResource.
Definition ResourceHandle.h:136
Definition Declarations.h:64
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Type for important GAL events.
Definition Descriptors.h:253
Definition Descriptors.h:177
Definition GameApplicationBase.h:32
Definition Declarations.h:9