1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GFX_VR_SERVICE_OCULUSSESSION_H
8 #define GFX_VR_SERVICE_OCULUSSESSION_H
10 #include "VRSession.h"
12 #include "moz_external_vr.h"
13 #include "mozilla/TimeStamp.h"
14 #include "mozilla/gfx/2D.h"
16 #include "oculus/ovr_capi_dynamic.h"
18 #include "ShaderDefinitionsD3D11.h" // for VertexShaderConstants and PixelShaderConstants
24 struct VertexShaderConstants
;
25 struct PixelShaderConstants
;
29 class OculusSession
: public VRSession
{
32 virtual ~OculusSession();
34 bool Initialize(mozilla::gfx::VRSystemState
& aSystemState
,
35 bool aDetectRuntimesOnly
) override
;
36 void Shutdown() override
;
37 void ProcessEvents(mozilla::gfx::VRSystemState
& aSystemState
) override
;
38 void StartFrame(mozilla::gfx::VRSystemState
& aSystemState
) override
;
39 bool StartPresentation() override
;
40 void StopPresentation() override
;
41 bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive
& aLayer
,
42 ID3D11Texture2D
* aTexture
) override
;
43 void VibrateHaptic(uint32_t aControllerIdx
, uint32_t aHapticIndex
,
44 float aIntensity
, float aDuration
) override
;
45 void StopVibrateHaptic(uint32_t aControllerIdx
) override
;
46 void StopAllHaptics() override
;
51 bool StartLib(ovrInitFlags aFlags
);
55 bool StartRendering();
57 bool CreateD3DObjects();
59 void DestroyShaders();
60 void CoverTransitions();
61 void UpdateVisibility();
62 bool ChangeVisibility(bool bVisible
);
63 bool InitState(mozilla::gfx::VRSystemState
& aSystemState
);
64 void UpdateStageParameters(mozilla::gfx::VRDisplayState
& aState
);
65 void UpdateEyeParameters(mozilla::gfx::VRSystemState
& aState
);
66 void UpdateHeadsetPose(mozilla::gfx::VRSystemState
& aState
);
67 void UpdateControllers(VRSystemState
& aState
);
68 void UpdateControllerInputs(VRSystemState
& aState
,
69 const ovrInputState
& aInputState
);
71 void EnumerateControllers(VRSystemState
& aState
,
72 const ovrInputState
& aInputState
);
73 void UpdateControllerPose(VRSystemState
& aState
,
74 const ovrInputState
& aInputState
);
75 void UpdateTelemetry(VRSystemState
& aSystemState
);
76 bool IsPresentationReady() const;
77 bool UpdateConstantBuffers();
81 ovrInitFlags mInitFlags
;
82 ovrTextureSwapChain mTextureSet
;
83 nsTArray
<RefPtr
<ID3D11RenderTargetView
>> mRTView
;
84 nsTArray
<RefPtr
<ID3D11Texture2D
>> mTexture
;
85 nsTArray
<RefPtr
<ID3D11ShaderResourceView
>> mSRV
;
87 ID3D11VertexShader
* mQuadVS
;
88 ID3D11PixelShader
* mQuadPS
;
89 RefPtr
<ID3D11SamplerState
> mLinearSamplerState
;
90 layers::VertexShaderConstants mVSConstants
;
91 layers::PixelShaderConstants mPSConstants
;
92 RefPtr
<ID3D11Buffer
> mVSConstantBuffer
;
93 RefPtr
<ID3D11Buffer
> mPSConstantBuffer
;
94 RefPtr
<ID3D11Buffer
> mVertexBuffer
;
95 RefPtr
<ID3D11InputLayout
> mInputLayout
;
97 IntSize mPresentationSize
;
98 ovrFovPort mFOVPort
[2];
100 // Most recent HMD eye poses, from start of frame
101 ovrPosef mFrameStartPose
[2];
103 float mRemainingVibrateTime
[2];
104 float mHapticPulseIntensity
[2];
105 TimeStamp mLastHapticUpdate
;
107 // The timestamp of the last ending presentation
108 TimeStamp mLastPresentationEnd
;
113 } // namespace mozilla
115 #endif // GFX_VR_SERVICE_OCULUSSESSION_H