/
VR.hs
77 lines (59 loc) · 1.93 KB
/
VR.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{-# LANGUAGE BangPatterns #-}
module Plugin.VR
( VRInitResult(..)
, openHMD
, openVR
, initVR
) where
import Plugin.Imports
import Plugin.Types
import qualified Godot.Methods as G
data VRInitResult
= InitVRSuccess
| InitVRFailed
data VRBackend
= OpenHMD OpenHMDConfig
| OpenVR
deriving Eq
instance Show VRBackend where
show (OpenHMD _) = "OpenHMD"
show OpenVR = "OpenVR"
newtype OpenHMDConfig = OpenHMDConfig GodotObject
deriving Eq
-- | Initialize and get the OpenHMD configuration object
openHMDConfig :: IO OpenHMDConfig
openHMDConfig = do
"res://addons/godot-openhmd/OpenHMDConfig.gdns"
& newNS' []
<&> OpenHMDConfig
-- | Get the OpenHMD ARVRInterface
openHMD :: IO GodotARVRInterface
openHMD = do
!cfg <- openHMDConfig
findInterface $ OpenHMD cfg
-- | Get the OpenVR ARVRInterface
openVR :: IO GodotARVRInterface
openVR = findInterface OpenVR
-- | Initialize the ARVRInterface and return the success/failure
initVR :: GodotNode -> GodotARVRInterface -> IO VRInitResult
initVR node vri =
G.initialize vri >>= \case
True -> initSuccess
False -> initFailed
where
initSuccess :: IO VRInitResult
initSuccess = do
G.get_viewport node >>= (`G.set_use_arvr` True)
-- G.get_viewport node >>= (`G.set_hdr` False) -- Not needed with GLES2 renderer
getSingleton Godot_OS "OS" >>= (`G.set_use_vsync` False) -- Vsync must be disabled or we're limited to 60fps
getSingleton Godot_Engine "Engine" >>= (`G.set_target_fps` 90) -- Boost FPS to 90 without vsync
InitVRSuccess <$ godotPrint "Initialized VR interface."
initFailed :: IO VRInitResult
initFailed = do
InitVRFailed <$ godotPrint "Failed to initialize VR interface."
-- | Find the interface for the given backend
findInterface :: VRBackend -> IO GodotARVRInterface
findInterface vri = do
vriStr <- toLowLevel $ pack $ show vri
getSingleton GodotARVRServer "ARVRServer"
>>= (`G.find_interface` vriStr)