OVRPlugin.cs 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565
  1. /************************************************************************************
  2. Copyright : Copyright 2017 Oculus VR, LLC. All Rights reserved.
  3. Licensed under the Oculus VR Rift SDK License Version 3.4.1 (the "License");
  4. you may not use the Oculus VR Rift SDK except in compliance with the License,
  5. which is provided at the time of installation or download, or which
  6. otherwise accompanies this software in either electronic or hard copy form.
  7. You may obtain a copy of the License at
  8. https://developer.oculus.com/licenses/sdk-3.4.1
  9. Unless required by applicable law or agreed to in writing, the Oculus VR SDK
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ************************************************************************************/
  15. #if !(UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || (UNITY_ANDROID && !UNITY_EDITOR))
  16. #define OVRPLUGIN_UNSUPPORTED_PLATFORM
  17. #endif
  18. using System;
  19. using System.Runtime.InteropServices;
  20. using UnityEngine;
  21. // Internal C# wrapper for OVRPlugin.
  22. internal static class OVRPlugin
  23. {
  24. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  25. public const bool isSupportedPlatform = false;
  26. #else
  27. public const bool isSupportedPlatform = true;
  28. #endif
  29. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  30. public static readonly System.Version wrapperVersion = _versionZero;
  31. #else
  32. public static readonly System.Version wrapperVersion = OVRP_1_27_0.version;
  33. #endif
  34. private static System.Version _version;
  35. public static System.Version version
  36. {
  37. get
  38. {
  39. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  40. Debug.LogWarning("Platform is not currently supported by OVRPlugin");
  41. return _versionZero;
  42. #else
  43. if (_version == null)
  44. {
  45. try
  46. {
  47. string pluginVersion = OVRP_1_1_0.ovrp_GetVersion();
  48. if (pluginVersion != null)
  49. {
  50. // Truncate unsupported trailing version info for System.Version. Original string is returned if not present.
  51. pluginVersion = pluginVersion.Split('-')[0];
  52. _version = new System.Version(pluginVersion);
  53. }
  54. else
  55. {
  56. _version = _versionZero;
  57. }
  58. }
  59. catch
  60. {
  61. _version = _versionZero;
  62. }
  63. // Unity 5.1.1f3-p3 have OVRPlugin version "0.5.0", which isn't accurate.
  64. if (_version == OVRP_0_5_0.version)
  65. _version = OVRP_0_1_0.version;
  66. if (_version > _versionZero && _version < OVRP_1_3_0.version)
  67. throw new PlatformNotSupportedException("Oculus Utilities version " + wrapperVersion + " is too new for OVRPlugin version " + _version.ToString() + ". Update to the latest version of Unity.");
  68. }
  69. return _version;
  70. #endif
  71. }
  72. }
  73. private static System.Version _nativeSDKVersion;
  74. public static System.Version nativeSDKVersion
  75. {
  76. get
  77. {
  78. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  79. return _versionZero;
  80. #else
  81. if (_nativeSDKVersion == null)
  82. {
  83. try
  84. {
  85. string sdkVersion = string.Empty;
  86. if (version >= OVRP_1_1_0.version)
  87. sdkVersion = OVRP_1_1_0.ovrp_GetNativeSDKVersion();
  88. else
  89. sdkVersion = _versionZero.ToString();
  90. if (sdkVersion != null)
  91. {
  92. // Truncate unsupported trailing version info for System.Version. Original string is returned if not present.
  93. sdkVersion = sdkVersion.Split('-')[0];
  94. _nativeSDKVersion = new System.Version(sdkVersion);
  95. }
  96. else
  97. {
  98. _nativeSDKVersion = _versionZero;
  99. }
  100. }
  101. catch
  102. {
  103. _nativeSDKVersion = _versionZero;
  104. }
  105. }
  106. return _nativeSDKVersion;
  107. #endif
  108. }
  109. }
  110. [StructLayout(LayoutKind.Sequential)]
  111. private class GUID
  112. {
  113. public int a;
  114. public short b;
  115. public short c;
  116. public byte d0;
  117. public byte d1;
  118. public byte d2;
  119. public byte d3;
  120. public byte d4;
  121. public byte d5;
  122. public byte d6;
  123. public byte d7;
  124. }
  125. public enum Bool
  126. {
  127. False = 0,
  128. True
  129. }
  130. public enum Result
  131. {
  132. /// Success
  133. Success = 0,
  134. /// Failure
  135. Failure = -1000,
  136. Failure_InvalidParameter = -1001,
  137. Failure_NotInitialized = -1002,
  138. Failure_InvalidOperation = -1003,
  139. Failure_Unsupported = -1004,
  140. Failure_NotYetImplemented = -1005,
  141. Failure_OperationFailed = -1006,
  142. Failure_InsufficientSize = -1007,
  143. }
  144. public enum CameraStatus
  145. {
  146. CameraStatus_None,
  147. CameraStatus_Connected,
  148. CameraStatus_Calibrating,
  149. CameraStatus_CalibrationFailed,
  150. CameraStatus_Calibrated,
  151. CameraStatus_EnumSize = 0x7fffffff
  152. }
  153. public enum Eye
  154. {
  155. None = -1,
  156. Left = 0,
  157. Right = 1,
  158. Count = 2
  159. }
  160. public enum Tracker
  161. {
  162. None = -1,
  163. Zero = 0,
  164. One = 1,
  165. Two = 2,
  166. Three = 3,
  167. Count,
  168. }
  169. public enum Node
  170. {
  171. None = -1,
  172. EyeLeft = 0,
  173. EyeRight = 1,
  174. EyeCenter = 2,
  175. HandLeft = 3,
  176. HandRight = 4,
  177. TrackerZero = 5,
  178. TrackerOne = 6,
  179. TrackerTwo = 7,
  180. TrackerThree = 8,
  181. Head = 9,
  182. DeviceObjectZero = 10,
  183. Count,
  184. }
  185. public enum Controller
  186. {
  187. None = 0,
  188. LTouch = 0x00000001,
  189. RTouch = 0x00000002,
  190. Touch = LTouch | RTouch,
  191. Remote = 0x00000004,
  192. Gamepad = 0x00000010,
  193. Touchpad = 0x08000000,
  194. LTrackedRemote = 0x01000000,
  195. RTrackedRemote = 0x02000000,
  196. Active = unchecked((int)0x80000000),
  197. All = ~None,
  198. }
  199. public enum TrackingOrigin
  200. {
  201. EyeLevel = 0,
  202. FloorLevel = 1,
  203. Count,
  204. }
  205. public enum RecenterFlags
  206. {
  207. Default = 0,
  208. Controllers = 0x40000000,
  209. IgnoreAll = unchecked((int)0x80000000),
  210. Count,
  211. }
  212. public enum BatteryStatus
  213. {
  214. Charging = 0,
  215. Discharging,
  216. Full,
  217. NotCharging,
  218. Unknown,
  219. }
  220. public enum EyeTextureFormat
  221. {
  222. Default = 0,
  223. R8G8B8A8_sRGB = 0,
  224. R8G8B8A8 = 1,
  225. R16G16B16A16_FP = 2,
  226. R11G11B10_FP = 3,
  227. B8G8R8A8_sRGB = 4,
  228. B8G8R8A8 = 5,
  229. R5G6B5 = 11,
  230. EnumSize = 0x7fffffff
  231. }
  232. public enum PlatformUI
  233. {
  234. None = -1,
  235. ConfirmQuit = 1,
  236. GlobalMenuTutorial, // Deprecated
  237. }
  238. public enum SystemRegion
  239. {
  240. Unspecified = 0,
  241. Japan,
  242. China,
  243. }
  244. public enum SystemHeadset
  245. {
  246. None = 0,
  247. GearVR_R320, // Note4 Innovator
  248. GearVR_R321, // S6 Innovator
  249. GearVR_R322, // Commercial 1
  250. GearVR_R323, // Commercial 2 (USB Type C)
  251. GearVR_R324, // Commercial 3 (USB Type C)
  252. GearVR_R325, // Commercial 4 (USB Type C)
  253. Oculus_Go,
  254. Rift_DK1 = 0x1000,
  255. Rift_DK2,
  256. Rift_CV1,
  257. }
  258. public enum OverlayShape
  259. {
  260. Quad = 0,
  261. Cylinder = 1,
  262. Cubemap = 2,
  263. OffcenterCubemap = 4,
  264. Equirect = 5,
  265. }
  266. public enum Step
  267. {
  268. Render = -1,
  269. Physics = 0,
  270. }
  271. public enum CameraDevice
  272. {
  273. None = 0,
  274. WebCamera0 = 100,
  275. WebCamera1 = 101,
  276. ZEDCamera = 300,
  277. }
  278. public enum CameraDeviceDepthSensingMode
  279. {
  280. Standard = 0,
  281. Fill = 1,
  282. }
  283. public enum CameraDeviceDepthQuality
  284. {
  285. Low = 0,
  286. Medium = 1,
  287. High = 2,
  288. }
  289. public enum TiledMultiResLevel
  290. {
  291. Off = 0,
  292. LMSLow = 1,
  293. LMSMedium = 2,
  294. LMSHigh = 3,
  295. EnumSize = 0x7FFFFFFF
  296. }
  297. [StructLayout(LayoutKind.Sequential)]
  298. public struct CameraDeviceIntrinsicsParameters
  299. {
  300. float fx; /* Focal length in pixels along x axis. */
  301. float fy; /* Focal length in pixels along y axis. */
  302. float cx; /* Optical center along x axis, defined in pixels (usually close to width/2). */
  303. float cy; /* Optical center along y axis, defined in pixels (usually close to height/2). */
  304. double disto0; /* Distortion factor : [ k1, k2, p1, p2, k3 ]. Radial (k1,k2,k3) and Tangential (p1,p2) distortion.*/
  305. double disto1;
  306. double disto2;
  307. double disto3;
  308. double disto4;
  309. float v_fov; /* Vertical field of view after stereo rectification, in degrees. */
  310. float h_fov; /* Horizontal field of view after stereo rectification, in degrees.*/
  311. float d_fov; /* Diagonal field of view after stereo rectification, in degrees.*/
  312. int w; /* Resolution width */
  313. int h; /* Resolution height */
  314. }
  315. private const int OverlayShapeFlagShift = 4;
  316. private enum OverlayFlag
  317. {
  318. None = unchecked((int)0x00000000),
  319. OnTop = unchecked((int)0x00000001),
  320. HeadLocked = unchecked((int)0x00000002),
  321. // Using the 5-8 bits for shapes, total 16 potential shapes can be supported 0x000000[0]0 -> 0x000000[F]0
  322. ShapeFlag_Quad = unchecked((int)OverlayShape.Quad << OverlayShapeFlagShift),
  323. ShapeFlag_Cylinder = unchecked((int)OverlayShape.Cylinder << OverlayShapeFlagShift),
  324. ShapeFlag_Cubemap = unchecked((int)OverlayShape.Cubemap << OverlayShapeFlagShift),
  325. ShapeFlag_OffcenterCubemap = unchecked((int)OverlayShape.OffcenterCubemap << OverlayShapeFlagShift),
  326. ShapeFlagRangeMask = unchecked((int)0xF << OverlayShapeFlagShift),
  327. }
  328. [StructLayout(LayoutKind.Sequential)]
  329. public struct Vector2f
  330. {
  331. public float x;
  332. public float y;
  333. }
  334. [StructLayout(LayoutKind.Sequential)]
  335. public struct Vector3f
  336. {
  337. public float x;
  338. public float y;
  339. public float z;
  340. public static readonly Vector3f zero = new Vector3f { x = 0.0f, y = 0.0f, z = 0.0f };
  341. public override string ToString()
  342. {
  343. return string.Format("{0}, {1}, {2}", x, y, z);
  344. }
  345. }
  346. [StructLayout(LayoutKind.Sequential)]
  347. public struct Quatf
  348. {
  349. public float x;
  350. public float y;
  351. public float z;
  352. public float w;
  353. public static readonly Quatf identity = new Quatf { x = 0.0f, y = 0.0f, z = 0.0f, w = 1.0f };
  354. public override string ToString()
  355. {
  356. return string.Format("{0}, {1}, {2}, {3}", x, y, z, w);
  357. }
  358. }
  359. [StructLayout(LayoutKind.Sequential)]
  360. public struct Posef
  361. {
  362. public Quatf Orientation;
  363. public Vector3f Position;
  364. public static readonly Posef identity = new Posef { Orientation = Quatf.identity, Position = Vector3f.zero };
  365. public override string ToString()
  366. {
  367. return string.Format("Position ({0}), Orientation({1})", Position, Orientation);
  368. }
  369. }
  370. [StructLayout(LayoutKind.Sequential)]
  371. public struct PoseStatef
  372. {
  373. public Posef Pose;
  374. public Vector3f Velocity;
  375. public Vector3f Acceleration;
  376. public Vector3f AngularVelocity;
  377. public Vector3f AngularAcceleration;
  378. double Time;
  379. }
  380. [StructLayout(LayoutKind.Sequential)]
  381. public struct ControllerState4
  382. {
  383. public uint ConnectedControllers;
  384. public uint Buttons;
  385. public uint Touches;
  386. public uint NearTouches;
  387. public float LIndexTrigger;
  388. public float RIndexTrigger;
  389. public float LHandTrigger;
  390. public float RHandTrigger;
  391. public Vector2f LThumbstick;
  392. public Vector2f RThumbstick;
  393. public Vector2f LTouchpad;
  394. public Vector2f RTouchpad;
  395. public byte LBatteryPercentRemaining;
  396. public byte RBatteryPercentRemaining;
  397. public byte LRecenterCount;
  398. public byte RRecenterCount;
  399. public byte Reserved_27;
  400. public byte Reserved_26;
  401. public byte Reserved_25;
  402. public byte Reserved_24;
  403. public byte Reserved_23;
  404. public byte Reserved_22;
  405. public byte Reserved_21;
  406. public byte Reserved_20;
  407. public byte Reserved_19;
  408. public byte Reserved_18;
  409. public byte Reserved_17;
  410. public byte Reserved_16;
  411. public byte Reserved_15;
  412. public byte Reserved_14;
  413. public byte Reserved_13;
  414. public byte Reserved_12;
  415. public byte Reserved_11;
  416. public byte Reserved_10;
  417. public byte Reserved_09;
  418. public byte Reserved_08;
  419. public byte Reserved_07;
  420. public byte Reserved_06;
  421. public byte Reserved_05;
  422. public byte Reserved_04;
  423. public byte Reserved_03;
  424. public byte Reserved_02;
  425. public byte Reserved_01;
  426. public byte Reserved_00;
  427. public ControllerState4(ControllerState2 cs)
  428. {
  429. ConnectedControllers = cs.ConnectedControllers;
  430. Buttons = cs.Buttons;
  431. Touches = cs.Touches;
  432. NearTouches = cs.NearTouches;
  433. LIndexTrigger = cs.LIndexTrigger;
  434. RIndexTrigger = cs.RIndexTrigger;
  435. LHandTrigger = cs.LHandTrigger;
  436. RHandTrigger = cs.RHandTrigger;
  437. LThumbstick = cs.LThumbstick;
  438. RThumbstick = cs.RThumbstick;
  439. LTouchpad = cs.LTouchpad;
  440. RTouchpad = cs.RTouchpad;
  441. LBatteryPercentRemaining = 0;
  442. RBatteryPercentRemaining = 0;
  443. LRecenterCount = 0;
  444. RRecenterCount = 0;
  445. Reserved_27 = 0;
  446. Reserved_26 = 0;
  447. Reserved_25 = 0;
  448. Reserved_24 = 0;
  449. Reserved_23 = 0;
  450. Reserved_22 = 0;
  451. Reserved_21 = 0;
  452. Reserved_20 = 0;
  453. Reserved_19 = 0;
  454. Reserved_18 = 0;
  455. Reserved_17 = 0;
  456. Reserved_16 = 0;
  457. Reserved_15 = 0;
  458. Reserved_14 = 0;
  459. Reserved_13 = 0;
  460. Reserved_12 = 0;
  461. Reserved_11 = 0;
  462. Reserved_10 = 0;
  463. Reserved_09 = 0;
  464. Reserved_08 = 0;
  465. Reserved_07 = 0;
  466. Reserved_06 = 0;
  467. Reserved_05 = 0;
  468. Reserved_04 = 0;
  469. Reserved_03 = 0;
  470. Reserved_02 = 0;
  471. Reserved_01 = 0;
  472. Reserved_00 = 0;
  473. }
  474. }
  475. [StructLayout(LayoutKind.Sequential)]
  476. public struct ControllerState2
  477. {
  478. public uint ConnectedControllers;
  479. public uint Buttons;
  480. public uint Touches;
  481. public uint NearTouches;
  482. public float LIndexTrigger;
  483. public float RIndexTrigger;
  484. public float LHandTrigger;
  485. public float RHandTrigger;
  486. public Vector2f LThumbstick;
  487. public Vector2f RThumbstick;
  488. public Vector2f LTouchpad;
  489. public Vector2f RTouchpad;
  490. public ControllerState2(ControllerState cs)
  491. {
  492. ConnectedControllers = cs.ConnectedControllers;
  493. Buttons = cs.Buttons;
  494. Touches = cs.Touches;
  495. NearTouches = cs.NearTouches;
  496. LIndexTrigger = cs.LIndexTrigger;
  497. RIndexTrigger = cs.RIndexTrigger;
  498. LHandTrigger = cs.LHandTrigger;
  499. RHandTrigger = cs.RHandTrigger;
  500. LThumbstick = cs.LThumbstick;
  501. RThumbstick = cs.RThumbstick;
  502. LTouchpad = new Vector2f() { x = 0.0f, y = 0.0f };
  503. RTouchpad = new Vector2f() { x = 0.0f, y = 0.0f };
  504. }
  505. }
  506. [StructLayout(LayoutKind.Sequential)]
  507. public struct ControllerState
  508. {
  509. public uint ConnectedControllers;
  510. public uint Buttons;
  511. public uint Touches;
  512. public uint NearTouches;
  513. public float LIndexTrigger;
  514. public float RIndexTrigger;
  515. public float LHandTrigger;
  516. public float RHandTrigger;
  517. public Vector2f LThumbstick;
  518. public Vector2f RThumbstick;
  519. }
  520. [StructLayout(LayoutKind.Sequential)]
  521. public struct HapticsBuffer
  522. {
  523. public IntPtr Samples;
  524. public int SamplesCount;
  525. }
  526. [StructLayout(LayoutKind.Sequential)]
  527. public struct HapticsState
  528. {
  529. public int SamplesAvailable;
  530. public int SamplesQueued;
  531. }
  532. [StructLayout(LayoutKind.Sequential)]
  533. public struct HapticsDesc
  534. {
  535. public int SampleRateHz;
  536. public int SampleSizeInBytes;
  537. public int MinimumSafeSamplesQueued;
  538. public int MinimumBufferSamplesCount;
  539. public int OptimalBufferSamplesCount;
  540. public int MaximumBufferSamplesCount;
  541. }
  542. [StructLayout(LayoutKind.Sequential)]
  543. public struct AppPerfFrameStats
  544. {
  545. public int HmdVsyncIndex;
  546. public int AppFrameIndex;
  547. public int AppDroppedFrameCount;
  548. public float AppMotionToPhotonLatency;
  549. public float AppQueueAheadTime;
  550. public float AppCpuElapsedTime;
  551. public float AppGpuElapsedTime;
  552. public int CompositorFrameIndex;
  553. public int CompositorDroppedFrameCount;
  554. public float CompositorLatency;
  555. public float CompositorCpuElapsedTime;
  556. public float CompositorGpuElapsedTime;
  557. public float CompositorCpuStartToGpuEndElapsedTime;
  558. public float CompositorGpuEndToVsyncElapsedTime;
  559. }
  560. public const int AppPerfFrameStatsMaxCount = 5;
  561. [StructLayout(LayoutKind.Sequential)]
  562. public struct AppPerfStats
  563. {
  564. [MarshalAs(UnmanagedType.ByValArray, SizeConst = AppPerfFrameStatsMaxCount)]
  565. public AppPerfFrameStats[] FrameStats;
  566. public int FrameStatsCount;
  567. public Bool AnyFrameStatsDropped;
  568. public float AdaptiveGpuPerformanceScale;
  569. }
  570. [StructLayout(LayoutKind.Sequential)]
  571. public struct Sizei
  572. {
  573. public int w;
  574. public int h;
  575. }
  576. [StructLayout(LayoutKind.Sequential)]
  577. public struct Sizef
  578. {
  579. public float w;
  580. public float h;
  581. }
  582. [StructLayout(LayoutKind.Sequential)]
  583. public struct Vector2i
  584. {
  585. public int x;
  586. public int y;
  587. }
  588. [StructLayout(LayoutKind.Sequential)]
  589. public struct Recti
  590. {
  591. Vector2i Pos;
  592. Sizei Size;
  593. }
  594. [StructLayout(LayoutKind.Sequential)]
  595. public struct Rectf
  596. {
  597. Vector2f Pos;
  598. Sizef Size;
  599. }
  600. [StructLayout(LayoutKind.Sequential)]
  601. public struct Frustumf
  602. {
  603. public float zNear;
  604. public float zFar;
  605. public float fovX;
  606. public float fovY;
  607. }
  608. [StructLayout(LayoutKind.Sequential)]
  609. public struct Frustumf2
  610. {
  611. public float zNear;
  612. public float zFar;
  613. public Fovf Fov;
  614. }
  615. public enum BoundaryType
  616. {
  617. OuterBoundary = 0x0001,
  618. PlayArea = 0x0100,
  619. }
  620. [StructLayout(LayoutKind.Sequential)]
  621. public struct BoundaryTestResult
  622. {
  623. public Bool IsTriggering;
  624. public float ClosestDistance;
  625. public Vector3f ClosestPoint;
  626. public Vector3f ClosestPointNormal;
  627. }
  628. [StructLayout(LayoutKind.Sequential)]
  629. public struct BoundaryLookAndFeel
  630. {
  631. public Colorf Color;
  632. }
  633. [StructLayout(LayoutKind.Sequential)]
  634. public struct BoundaryGeometry
  635. {
  636. public BoundaryType BoundaryType;
  637. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
  638. public Vector3f[] Points;
  639. public int PointsCount;
  640. }
  641. [StructLayout(LayoutKind.Sequential)]
  642. public struct Colorf
  643. {
  644. public float r;
  645. public float g;
  646. public float b;
  647. public float a;
  648. }
  649. [StructLayout(LayoutKind.Sequential)]
  650. public struct Fovf
  651. {
  652. public float UpTan;
  653. public float DownTan;
  654. public float LeftTan;
  655. public float RightTan;
  656. }
  657. [StructLayout(LayoutKind.Sequential)]
  658. public struct CameraIntrinsics
  659. {
  660. public bool IsValid;
  661. public double LastChangedTimeSeconds;
  662. public Fovf FOVPort;
  663. public float VirtualNearPlaneDistanceMeters;
  664. public float VirtualFarPlaneDistanceMeters;
  665. public Sizei ImageSensorPixelResolution;
  666. }
  667. [StructLayout(LayoutKind.Sequential)]
  668. public struct CameraExtrinsics
  669. {
  670. public bool IsValid;
  671. public double LastChangedTimeSeconds;
  672. public CameraStatus CameraStatusData;
  673. public Node AttachedToNode;
  674. public Posef RelativePose;
  675. }
  676. public enum LayerLayout
  677. {
  678. Stereo = 0,
  679. Mono = 1,
  680. DoubleWide = 2,
  681. Array = 3,
  682. EnumSize = 0xF
  683. }
  684. public enum LayerFlags
  685. {
  686. Static = (1 << 0),
  687. LoadingScreen = (1 << 1),
  688. SymmetricFov = (1 << 2),
  689. TextureOriginAtBottomLeft = (1 << 3),
  690. ChromaticAberrationCorrection = (1 << 4),
  691. NoAllocation = (1 << 5),
  692. ProtectedContent = (1 << 6),
  693. }
  694. [StructLayout(LayoutKind.Sequential)]
  695. public struct LayerDesc
  696. {
  697. public OverlayShape Shape;
  698. public LayerLayout Layout;
  699. public Sizei TextureSize;
  700. public int MipLevels;
  701. public int SampleCount;
  702. public EyeTextureFormat Format;
  703. public int LayerFlags;
  704. //Eye FOV-only members.
  705. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
  706. public Fovf[] Fov;
  707. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
  708. public Rectf[] VisibleRect;
  709. public Sizei MaxViewportSize;
  710. EyeTextureFormat DepthFormat;
  711. public override string ToString()
  712. {
  713. string delim = ", ";
  714. return Shape.ToString()
  715. + delim + Layout.ToString()
  716. + delim + TextureSize.w.ToString() + "x" + TextureSize.h.ToString()
  717. + delim + MipLevels.ToString()
  718. + delim + SampleCount.ToString()
  719. + delim + Format.ToString()
  720. + delim + LayerFlags.ToString();
  721. }
  722. }
  723. [StructLayout(LayoutKind.Sequential)]
  724. public struct LayerSubmit
  725. {
  726. int LayerId;
  727. int TextureStage;
  728. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
  729. Recti[] ViewportRect;
  730. Posef Pose;
  731. int LayerSubmitFlags;
  732. }
  733. public static bool initialized
  734. {
  735. get
  736. {
  737. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  738. return false;
  739. #else
  740. return OVRP_1_1_0.ovrp_GetInitialized() == OVRPlugin.Bool.True;
  741. #endif
  742. }
  743. }
  744. public static bool chromatic
  745. {
  746. get
  747. {
  748. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  749. return false;
  750. #else
  751. if (version >= OVRP_1_7_0.version)
  752. return initialized && OVRP_1_7_0.ovrp_GetAppChromaticCorrection() == OVRPlugin.Bool.True;
  753. #if UNITY_ANDROID && !UNITY_EDITOR
  754. return false;
  755. #else
  756. return true;
  757. #endif
  758. #endif
  759. }
  760. set
  761. {
  762. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  763. return;
  764. #else
  765. if (initialized && version >= OVRP_1_7_0.version)
  766. OVRP_1_7_0.ovrp_SetAppChromaticCorrection(ToBool(value));
  767. #endif
  768. }
  769. }
  770. public static bool monoscopic
  771. {
  772. get
  773. {
  774. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  775. return false;
  776. #else
  777. return initialized && OVRP_1_1_0.ovrp_GetAppMonoscopic() == OVRPlugin.Bool.True;
  778. #endif
  779. }
  780. set
  781. {
  782. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  783. return;
  784. #else
  785. if (initialized)
  786. {
  787. OVRP_1_1_0.ovrp_SetAppMonoscopic(ToBool(value));
  788. }
  789. #endif
  790. }
  791. }
  792. public static bool rotation
  793. {
  794. get
  795. {
  796. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  797. return false;
  798. #else
  799. return initialized && OVRP_1_1_0.ovrp_GetTrackingOrientationEnabled() == Bool.True;
  800. #endif
  801. }
  802. set
  803. {
  804. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  805. return;
  806. #else
  807. if (initialized)
  808. {
  809. OVRP_1_1_0.ovrp_SetTrackingOrientationEnabled(ToBool(value));
  810. }
  811. #endif
  812. }
  813. }
  814. public static bool position
  815. {
  816. get
  817. {
  818. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  819. return false;
  820. #else
  821. return initialized && OVRP_1_1_0.ovrp_GetTrackingPositionEnabled() == Bool.True;
  822. #endif
  823. }
  824. set
  825. {
  826. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  827. return;
  828. #else
  829. if (initialized)
  830. {
  831. OVRP_1_1_0.ovrp_SetTrackingPositionEnabled(ToBool(value));
  832. }
  833. #endif
  834. }
  835. }
  836. public static bool useIPDInPositionTracking
  837. {
  838. get
  839. {
  840. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  841. return false;
  842. #else
  843. if (initialized && version >= OVRP_1_6_0.version)
  844. return OVRP_1_6_0.ovrp_GetTrackingIPDEnabled() == OVRPlugin.Bool.True;
  845. return true;
  846. #endif
  847. }
  848. set
  849. {
  850. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  851. return;
  852. #else
  853. if (initialized && version >= OVRP_1_6_0.version)
  854. OVRP_1_6_0.ovrp_SetTrackingIPDEnabled(ToBool(value));
  855. #endif
  856. }
  857. }
  858. public static bool positionSupported
  859. {
  860. get
  861. {
  862. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  863. return false;
  864. #else
  865. return initialized && OVRP_1_1_0.ovrp_GetTrackingPositionSupported() == Bool.True;
  866. #endif
  867. }
  868. }
  869. public static bool positionTracked
  870. {
  871. get
  872. {
  873. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  874. return false;
  875. #else
  876. return initialized && OVRP_1_1_0.ovrp_GetNodePositionTracked(Node.EyeCenter) == Bool.True;
  877. #endif
  878. }
  879. }
  880. public static bool powerSaving
  881. {
  882. get
  883. {
  884. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  885. return false;
  886. #else
  887. return initialized && OVRP_1_1_0.ovrp_GetSystemPowerSavingMode() == Bool.True;
  888. #endif
  889. }
  890. }
  891. public static bool hmdPresent
  892. {
  893. get
  894. {
  895. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  896. return false;
  897. #else
  898. return initialized && OVRP_1_1_0.ovrp_GetNodePresent(Node.EyeCenter) == Bool.True;
  899. #endif
  900. }
  901. }
  902. public static bool userPresent
  903. {
  904. get
  905. {
  906. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  907. return false;
  908. #else
  909. return initialized && OVRP_1_1_0.ovrp_GetUserPresent() == Bool.True;
  910. #endif
  911. }
  912. }
  913. public static bool headphonesPresent
  914. {
  915. get
  916. {
  917. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  918. return false;
  919. #else
  920. return initialized && OVRP_1_3_0.ovrp_GetSystemHeadphonesPresent() == OVRPlugin.Bool.True;
  921. #endif
  922. }
  923. }
  924. public static int recommendedMSAALevel
  925. {
  926. get
  927. {
  928. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  929. return 2;
  930. #else
  931. if (initialized && version >= OVRP_1_6_0.version)
  932. return OVRP_1_6_0.ovrp_GetSystemRecommendedMSAALevel();
  933. else
  934. return 2;
  935. #endif
  936. }
  937. }
  938. public static SystemRegion systemRegion
  939. {
  940. get
  941. {
  942. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  943. return SystemRegion.Unspecified;
  944. #else
  945. if (initialized && version >= OVRP_1_5_0.version)
  946. return OVRP_1_5_0.ovrp_GetSystemRegion();
  947. else
  948. return SystemRegion.Unspecified;
  949. #endif
  950. }
  951. }
  952. #if !OVRPLUGIN_UNSUPPORTED_PLATFORM
  953. private static GUID _nativeAudioOutGuid = new OVRPlugin.GUID();
  954. private static Guid _cachedAudioOutGuid;
  955. private static string _cachedAudioOutString;
  956. #endif
  957. public static string audioOutId
  958. {
  959. get
  960. {
  961. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  962. return string.Empty;
  963. #else
  964. try
  965. {
  966. if (_nativeAudioOutGuid == null)
  967. _nativeAudioOutGuid = new OVRPlugin.GUID();
  968. IntPtr ptr = OVRP_1_1_0.ovrp_GetAudioOutId();
  969. if (ptr != IntPtr.Zero)
  970. {
  971. Marshal.PtrToStructure(ptr, _nativeAudioOutGuid);
  972. Guid managedGuid = new Guid(
  973. _nativeAudioOutGuid.a,
  974. _nativeAudioOutGuid.b,
  975. _nativeAudioOutGuid.c,
  976. _nativeAudioOutGuid.d0,
  977. _nativeAudioOutGuid.d1,
  978. _nativeAudioOutGuid.d2,
  979. _nativeAudioOutGuid.d3,
  980. _nativeAudioOutGuid.d4,
  981. _nativeAudioOutGuid.d5,
  982. _nativeAudioOutGuid.d6,
  983. _nativeAudioOutGuid.d7);
  984. if (managedGuid != _cachedAudioOutGuid)
  985. {
  986. _cachedAudioOutGuid = managedGuid;
  987. _cachedAudioOutString = _cachedAudioOutGuid.ToString();
  988. }
  989. return _cachedAudioOutString;
  990. }
  991. }
  992. catch { }
  993. return string.Empty;
  994. #endif
  995. }
  996. }
  997. #if !OVRPLUGIN_UNSUPPORTED_PLATFORM
  998. private static GUID _nativeAudioInGuid = new OVRPlugin.GUID();
  999. private static Guid _cachedAudioInGuid;
  1000. private static string _cachedAudioInString;
  1001. #endif
  1002. public static string audioInId
  1003. {
  1004. get
  1005. {
  1006. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1007. return string.Empty;
  1008. #else
  1009. try
  1010. {
  1011. if (_nativeAudioInGuid == null)
  1012. _nativeAudioInGuid = new OVRPlugin.GUID();
  1013. IntPtr ptr = OVRP_1_1_0.ovrp_GetAudioInId();
  1014. if (ptr != IntPtr.Zero)
  1015. {
  1016. Marshal.PtrToStructure(ptr, _nativeAudioInGuid);
  1017. Guid managedGuid = new Guid(
  1018. _nativeAudioInGuid.a,
  1019. _nativeAudioInGuid.b,
  1020. _nativeAudioInGuid.c,
  1021. _nativeAudioInGuid.d0,
  1022. _nativeAudioInGuid.d1,
  1023. _nativeAudioInGuid.d2,
  1024. _nativeAudioInGuid.d3,
  1025. _nativeAudioInGuid.d4,
  1026. _nativeAudioInGuid.d5,
  1027. _nativeAudioInGuid.d6,
  1028. _nativeAudioInGuid.d7);
  1029. if (managedGuid != _cachedAudioInGuid)
  1030. {
  1031. _cachedAudioInGuid = managedGuid;
  1032. _cachedAudioInString = _cachedAudioInGuid.ToString();
  1033. }
  1034. return _cachedAudioInString;
  1035. }
  1036. }
  1037. catch { }
  1038. return string.Empty;
  1039. #endif
  1040. }
  1041. }
  1042. public static bool hasVrFocus
  1043. {
  1044. get
  1045. {
  1046. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1047. return false;
  1048. #else
  1049. return OVRP_1_1_0.ovrp_GetAppHasVrFocus() == Bool.True;
  1050. #endif
  1051. }
  1052. }
  1053. public static bool hasInputFocus
  1054. {
  1055. get
  1056. {
  1057. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1058. return true;
  1059. #else
  1060. if (version >= OVRP_1_18_0.version)
  1061. {
  1062. Bool inputFocus = Bool.False;
  1063. Result result = OVRP_1_18_0.ovrp_GetAppHasInputFocus(out inputFocus);
  1064. if (Result.Success == result)
  1065. return inputFocus == Bool.True;
  1066. else
  1067. {
  1068. //Debug.LogWarning("ovrp_GetAppHasInputFocus return " + result);
  1069. return false;
  1070. }
  1071. }
  1072. return true;
  1073. #endif
  1074. }
  1075. }
  1076. public static bool shouldQuit
  1077. {
  1078. get
  1079. {
  1080. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1081. return false;
  1082. #else
  1083. return OVRP_1_1_0.ovrp_GetAppShouldQuit() == Bool.True;
  1084. #endif
  1085. }
  1086. }
  1087. public static bool shouldRecenter
  1088. {
  1089. get
  1090. {
  1091. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1092. return false;
  1093. #else
  1094. return OVRP_1_1_0.ovrp_GetAppShouldRecenter() == Bool.True;
  1095. #endif
  1096. }
  1097. }
  1098. public static string productName
  1099. {
  1100. get
  1101. {
  1102. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1103. return string.Empty;
  1104. #else
  1105. return OVRP_1_1_0.ovrp_GetSystemProductName();
  1106. #endif
  1107. }
  1108. }
  1109. public static string latency
  1110. {
  1111. get
  1112. {
  1113. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1114. return string.Empty;
  1115. #else
  1116. return OVRP_1_1_0.ovrp_GetAppLatencyTimings();
  1117. #endif
  1118. }
  1119. }
  1120. public static float eyeDepth
  1121. {
  1122. get
  1123. {
  1124. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1125. return 0.0f;
  1126. #else
  1127. return OVRP_1_1_0.ovrp_GetUserEyeDepth();
  1128. #endif
  1129. }
  1130. set
  1131. {
  1132. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1133. return;
  1134. #else
  1135. OVRP_1_1_0.ovrp_SetUserEyeDepth(value);
  1136. #endif
  1137. }
  1138. }
  1139. public static float eyeHeight
  1140. {
  1141. get
  1142. {
  1143. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1144. return 0.0f;
  1145. #else
  1146. return OVRP_1_1_0.ovrp_GetUserEyeHeight();
  1147. #endif
  1148. }
  1149. set
  1150. {
  1151. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1152. return;
  1153. #else
  1154. OVRP_1_1_0.ovrp_SetUserEyeHeight(value);
  1155. #endif
  1156. }
  1157. }
  1158. public static float batteryLevel
  1159. {
  1160. get
  1161. {
  1162. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1163. return 0.0f;
  1164. #else
  1165. return OVRP_1_1_0.ovrp_GetSystemBatteryLevel();
  1166. #endif
  1167. }
  1168. }
  1169. public static float batteryTemperature
  1170. {
  1171. get
  1172. {
  1173. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1174. return 0.0f;
  1175. #else
  1176. return OVRP_1_1_0.ovrp_GetSystemBatteryTemperature();
  1177. #endif
  1178. }
  1179. }
  1180. public static int cpuLevel
  1181. {
  1182. get
  1183. {
  1184. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1185. return 0;
  1186. #else
  1187. return OVRP_1_1_0.ovrp_GetSystemCpuLevel();
  1188. #endif
  1189. }
  1190. set
  1191. {
  1192. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1193. return;
  1194. #else
  1195. OVRP_1_1_0.ovrp_SetSystemCpuLevel(value);
  1196. #endif
  1197. }
  1198. }
  1199. public static int gpuLevel
  1200. {
  1201. get
  1202. {
  1203. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1204. return 0;
  1205. #else
  1206. return OVRP_1_1_0.ovrp_GetSystemGpuLevel();
  1207. #endif
  1208. }
  1209. set
  1210. {
  1211. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1212. return;
  1213. #else
  1214. OVRP_1_1_0.ovrp_SetSystemGpuLevel(value);
  1215. #endif
  1216. }
  1217. }
  1218. public static int vsyncCount
  1219. {
  1220. get
  1221. {
  1222. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1223. return 0;
  1224. #else
  1225. return OVRP_1_1_0.ovrp_GetSystemVSyncCount();
  1226. #endif
  1227. }
  1228. set
  1229. {
  1230. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1231. return;
  1232. #else
  1233. OVRP_1_2_0.ovrp_SetSystemVSyncCount(value);
  1234. #endif
  1235. }
  1236. }
  1237. public static float systemVolume
  1238. {
  1239. get
  1240. {
  1241. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1242. return 0.0f;
  1243. #else
  1244. return OVRP_1_1_0.ovrp_GetSystemVolume();
  1245. #endif
  1246. }
  1247. }
  1248. public static float ipd
  1249. {
  1250. get
  1251. {
  1252. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1253. return 0.0f;
  1254. #else
  1255. return OVRP_1_1_0.ovrp_GetUserIPD();
  1256. #endif
  1257. }
  1258. set
  1259. {
  1260. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1261. return;
  1262. #else
  1263. OVRP_1_1_0.ovrp_SetUserIPD(value);
  1264. #endif
  1265. }
  1266. }
  1267. public static bool occlusionMesh
  1268. {
  1269. get
  1270. {
  1271. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1272. return false;
  1273. #else
  1274. return OVRP_1_3_0.ovrp_GetEyeOcclusionMeshEnabled() == Bool.True;
  1275. #endif
  1276. }
  1277. set
  1278. {
  1279. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1280. return;
  1281. #else
  1282. OVRP_1_3_0.ovrp_SetEyeOcclusionMeshEnabled(ToBool(value));
  1283. #endif
  1284. }
  1285. }
  1286. public static BatteryStatus batteryStatus
  1287. {
  1288. get
  1289. {
  1290. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1291. return default(BatteryStatus);
  1292. #else
  1293. return OVRP_1_1_0.ovrp_GetSystemBatteryStatus();
  1294. #endif
  1295. }
  1296. }
  1297. public static Frustumf GetEyeFrustum(Eye eyeId)
  1298. {
  1299. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1300. return new Frustumf();
  1301. #else
  1302. return OVRP_1_1_0.ovrp_GetNodeFrustum((Node)eyeId);
  1303. #endif
  1304. }
  1305. public static Sizei GetEyeTextureSize(Eye eyeId)
  1306. {
  1307. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1308. return new Sizei();
  1309. #else
  1310. return OVRP_0_1_0.ovrp_GetEyeTextureSize(eyeId);
  1311. #endif
  1312. }
  1313. public static Posef GetTrackerPose(Tracker trackerId)
  1314. {
  1315. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1316. return Posef.identity;
  1317. #else
  1318. return GetNodePose((Node)((int)trackerId + (int)Node.TrackerZero), Step.Render);
  1319. #endif
  1320. }
  1321. public static Frustumf GetTrackerFrustum(Tracker trackerId)
  1322. {
  1323. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1324. return new Frustumf();
  1325. #else
  1326. return OVRP_1_1_0.ovrp_GetNodeFrustum((Node)((int)trackerId + (int)Node.TrackerZero));
  1327. #endif
  1328. }
  1329. public static bool ShowUI(PlatformUI ui)
  1330. {
  1331. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1332. return false;
  1333. #else
  1334. return OVRP_1_1_0.ovrp_ShowSystemUI(ui) == Bool.True;
  1335. #endif
  1336. }
  1337. public static bool EnqueueSubmitLayer(bool onTop, bool headLocked, IntPtr leftTexture, IntPtr rightTexture, int layerId, int frameIndex, Posef pose, Vector3f scale, int layerIndex = 0, OverlayShape shape = OverlayShape.Quad)
  1338. {
  1339. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1340. return false;
  1341. #else
  1342. if (version >= OVRP_1_6_0.version)
  1343. {
  1344. uint flags = (uint)OverlayFlag.None;
  1345. if (onTop)
  1346. flags |= (uint)OverlayFlag.OnTop;
  1347. if (headLocked)
  1348. flags |= (uint)OverlayFlag.HeadLocked;
  1349. if (shape == OverlayShape.Cylinder || shape == OverlayShape.Cubemap)
  1350. {
  1351. #if UNITY_ANDROID
  1352. if (version >= OVRP_1_7_0.version)
  1353. flags |= (uint)(shape) << OverlayShapeFlagShift;
  1354. else
  1355. #else
  1356. if (shape == OverlayShape.Cubemap && version >= OVRP_1_10_0.version)
  1357. flags |= (uint)(shape) << OverlayShapeFlagShift;
  1358. else if (shape == OverlayShape.Cylinder && version >= OVRP_1_16_0.version)
  1359. flags |= (uint)(shape) << OverlayShapeFlagShift;
  1360. else
  1361. #endif
  1362. return false;
  1363. }
  1364. if (shape == OverlayShape.OffcenterCubemap)
  1365. {
  1366. #if UNITY_ANDROID
  1367. if (version >= OVRP_1_11_0.version)
  1368. flags |= (uint)(shape) << OverlayShapeFlagShift;
  1369. else
  1370. #endif
  1371. return false;
  1372. }
  1373. if (shape == OverlayShape.Equirect)
  1374. {
  1375. #if UNITY_ANDROID
  1376. if (version >= OVRP_1_21_0.version)
  1377. flags |= (uint)(shape) << OverlayShapeFlagShift;
  1378. else
  1379. #endif
  1380. return false;
  1381. }
  1382. if (version >= OVRP_1_15_0.version && layerId != -1)
  1383. return OVRP_1_15_0.ovrp_EnqueueSubmitLayer(flags, leftTexture, rightTexture, layerId, frameIndex, ref pose, ref scale, layerIndex) == Result.Success;
  1384. return OVRP_1_6_0.ovrp_SetOverlayQuad3(flags, leftTexture, rightTexture, IntPtr.Zero, pose, scale, layerIndex) == Bool.True;
  1385. }
  1386. if (layerIndex != 0)
  1387. return false;
  1388. return OVRP_0_1_1.ovrp_SetOverlayQuad2(ToBool(onTop), ToBool(headLocked), leftTexture, IntPtr.Zero, pose, scale) == Bool.True;
  1389. #endif
  1390. }
  1391. public static LayerDesc CalculateLayerDesc(OverlayShape shape, LayerLayout layout, Sizei textureSize,
  1392. int mipLevels, int sampleCount, EyeTextureFormat format, int layerFlags)
  1393. {
  1394. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1395. return new LayerDesc();
  1396. #else
  1397. LayerDesc layerDesc = new LayerDesc();
  1398. if (version >= OVRP_1_15_0.version)
  1399. {
  1400. OVRP_1_15_0.ovrp_CalculateLayerDesc (shape, layout, ref textureSize,
  1401. mipLevels, sampleCount, format, layerFlags, ref layerDesc);
  1402. }
  1403. return layerDesc;
  1404. #endif
  1405. }
  1406. public static bool EnqueueSetupLayer(LayerDesc desc, IntPtr layerID)
  1407. {
  1408. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1409. return false;
  1410. #else
  1411. if (version >= OVRP_1_15_0.version)
  1412. return OVRP_1_15_0.ovrp_EnqueueSetupLayer(ref desc, layerID) == Result.Success;
  1413. return false;
  1414. #endif
  1415. }
  1416. public static bool EnqueueDestroyLayer(IntPtr layerID)
  1417. {
  1418. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1419. return false;
  1420. #else
  1421. if (version >= OVRP_1_15_0.version)
  1422. return OVRP_1_15_0.ovrp_EnqueueDestroyLayer(layerID) == Result.Success;
  1423. return false;
  1424. #endif
  1425. }
  1426. public static IntPtr GetLayerTexture(int layerId, int stage, Eye eyeId)
  1427. {
  1428. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1429. return IntPtr.Zero;
  1430. #else
  1431. IntPtr textureHandle = IntPtr.Zero;
  1432. if (version >= OVRP_1_15_0.version)
  1433. OVRP_1_15_0.ovrp_GetLayerTexturePtr(layerId, stage, eyeId, ref textureHandle);
  1434. return textureHandle;
  1435. #endif
  1436. }
  1437. public static int GetLayerTextureStageCount(int layerId)
  1438. {
  1439. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1440. return 1;
  1441. #else
  1442. int stageCount = 1;
  1443. if (version >= OVRP_1_15_0.version)
  1444. OVRP_1_15_0.ovrp_GetLayerTextureStageCount(layerId, ref stageCount);
  1445. return stageCount;
  1446. #endif
  1447. }
  1448. public static bool UpdateNodePhysicsPoses(int frameIndex, double predictionSeconds)
  1449. {
  1450. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1451. return false;
  1452. #else
  1453. if (version >= OVRP_1_8_0.version)
  1454. return OVRP_1_8_0.ovrp_Update2((int)Step.Physics, frameIndex, predictionSeconds) == Bool.True;
  1455. return false;
  1456. #endif
  1457. }
  1458. public static Posef GetNodePose(Node nodeId, Step stepId)
  1459. {
  1460. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1461. return Posef.identity;
  1462. #else
  1463. if (version >= OVRP_1_12_0.version)
  1464. return OVRP_1_12_0.ovrp_GetNodePoseState(stepId, nodeId).Pose;
  1465. if (version >= OVRP_1_8_0.version && stepId == Step.Physics)
  1466. return OVRP_1_8_0.ovrp_GetNodePose2(0, nodeId);
  1467. return OVRP_0_1_2.ovrp_GetNodePose(nodeId);
  1468. #endif
  1469. }
  1470. public static Vector3f GetNodeVelocity(Node nodeId, Step stepId)
  1471. {
  1472. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1473. return new Vector3f();
  1474. #else
  1475. if (version >= OVRP_1_12_0.version)
  1476. return OVRP_1_12_0.ovrp_GetNodePoseState(stepId, nodeId).Velocity;
  1477. if (version >= OVRP_1_8_0.version && stepId == Step.Physics)
  1478. return OVRP_1_8_0.ovrp_GetNodeVelocity2(0, nodeId).Position;
  1479. return OVRP_0_1_3.ovrp_GetNodeVelocity(nodeId).Position;
  1480. #endif
  1481. }
  1482. public static Vector3f GetNodeAngularVelocity(Node nodeId, Step stepId)
  1483. {
  1484. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1485. return new Vector3f();
  1486. #else
  1487. if (version >= OVRP_1_12_0.version)
  1488. return OVRP_1_12_0.ovrp_GetNodePoseState(stepId, nodeId).AngularVelocity;
  1489. return new Vector3f(); //TODO: Convert legacy quat to vec3?
  1490. #endif
  1491. }
  1492. public static Vector3f GetNodeAcceleration(Node nodeId, Step stepId)
  1493. {
  1494. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1495. return new Vector3f();
  1496. #else
  1497. if (version >= OVRP_1_12_0.version)
  1498. return OVRP_1_12_0.ovrp_GetNodePoseState(stepId, nodeId).Acceleration;
  1499. if (version >= OVRP_1_8_0.version && stepId == Step.Physics)
  1500. return OVRP_1_8_0.ovrp_GetNodeAcceleration2(0, nodeId).Position;
  1501. return OVRP_0_1_3.ovrp_GetNodeAcceleration(nodeId).Position;
  1502. #endif
  1503. }
  1504. public static Vector3f GetNodeAngularAcceleration(Node nodeId, Step stepId)
  1505. {
  1506. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1507. return new Vector3f();
  1508. #else
  1509. if (version >= OVRP_1_12_0.version)
  1510. return OVRP_1_12_0.ovrp_GetNodePoseState(stepId, nodeId).AngularAcceleration;
  1511. return new Vector3f(); //TODO: Convert legacy quat to vec3?
  1512. #endif
  1513. }
  1514. public static bool GetNodePresent(Node nodeId)
  1515. {
  1516. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1517. return false;
  1518. #else
  1519. return OVRP_1_1_0.ovrp_GetNodePresent(nodeId) == Bool.True;
  1520. #endif
  1521. }
  1522. public static bool GetNodeOrientationTracked(Node nodeId)
  1523. {
  1524. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1525. return false;
  1526. #else
  1527. return OVRP_1_1_0.ovrp_GetNodeOrientationTracked(nodeId) == Bool.True;
  1528. #endif
  1529. }
  1530. public static bool GetNodePositionTracked(Node nodeId)
  1531. {
  1532. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1533. return false;
  1534. #else
  1535. return OVRP_1_1_0.ovrp_GetNodePositionTracked(nodeId) == Bool.True;
  1536. #endif
  1537. }
  1538. public static ControllerState GetControllerState(uint controllerMask)
  1539. {
  1540. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1541. return new ControllerState();
  1542. #else
  1543. return OVRP_1_1_0.ovrp_GetControllerState(controllerMask);
  1544. #endif
  1545. }
  1546. public static ControllerState2 GetControllerState2(uint controllerMask)
  1547. {
  1548. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1549. return new ControllerState2();
  1550. #else
  1551. if (version >= OVRP_1_12_0.version)
  1552. {
  1553. return OVRP_1_12_0.ovrp_GetControllerState2(controllerMask);
  1554. }
  1555. return new ControllerState2(OVRP_1_1_0.ovrp_GetControllerState(controllerMask));
  1556. #endif
  1557. }
  1558. public static ControllerState4 GetControllerState4(uint controllerMask)
  1559. {
  1560. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1561. return new ControllerState4();
  1562. #else
  1563. if (version >= OVRP_1_16_0.version)
  1564. {
  1565. ControllerState4 controllerState = new ControllerState4();
  1566. OVRP_1_16_0.ovrp_GetControllerState4(controllerMask, ref controllerState);
  1567. return controllerState;
  1568. }
  1569. return new ControllerState4(GetControllerState2(controllerMask));
  1570. #endif
  1571. }
  1572. public static bool SetControllerVibration(uint controllerMask, float frequency, float amplitude)
  1573. {
  1574. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1575. return false;
  1576. #else
  1577. return OVRP_0_1_2.ovrp_SetControllerVibration(controllerMask, frequency, amplitude) == Bool.True;
  1578. #endif
  1579. }
  1580. public static HapticsDesc GetControllerHapticsDesc(uint controllerMask)
  1581. {
  1582. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1583. return new HapticsDesc();
  1584. #else
  1585. if (version >= OVRP_1_6_0.version)
  1586. {
  1587. return OVRP_1_6_0.ovrp_GetControllerHapticsDesc(controllerMask);
  1588. }
  1589. else
  1590. {
  1591. return new HapticsDesc();
  1592. }
  1593. #endif
  1594. }
  1595. public static HapticsState GetControllerHapticsState(uint controllerMask)
  1596. {
  1597. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1598. return new HapticsState();
  1599. #else
  1600. if (version >= OVRP_1_6_0.version)
  1601. {
  1602. return OVRP_1_6_0.ovrp_GetControllerHapticsState(controllerMask);
  1603. }
  1604. else
  1605. {
  1606. return new HapticsState();
  1607. }
  1608. #endif
  1609. }
  1610. public static bool SetControllerHaptics(uint controllerMask, HapticsBuffer hapticsBuffer)
  1611. {
  1612. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1613. return false;
  1614. #else
  1615. if (version >= OVRP_1_6_0.version)
  1616. {
  1617. return OVRP_1_6_0.ovrp_SetControllerHaptics(controllerMask, hapticsBuffer) == Bool.True;
  1618. }
  1619. else
  1620. {
  1621. return false;
  1622. }
  1623. #endif
  1624. }
  1625. public static float GetEyeRecommendedResolutionScale()
  1626. {
  1627. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1628. return 1.0f;
  1629. #else
  1630. if (version >= OVRP_1_6_0.version)
  1631. {
  1632. return OVRP_1_6_0.ovrp_GetEyeRecommendedResolutionScale();
  1633. }
  1634. else
  1635. {
  1636. return 1.0f;
  1637. }
  1638. #endif
  1639. }
  1640. public static float GetAppCpuStartToGpuEndTime()
  1641. {
  1642. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1643. return 0.0f;
  1644. #else
  1645. if (version >= OVRP_1_6_0.version)
  1646. {
  1647. return OVRP_1_6_0.ovrp_GetAppCpuStartToGpuEndTime();
  1648. }
  1649. else
  1650. {
  1651. return 0.0f;
  1652. }
  1653. #endif
  1654. }
  1655. public static bool GetBoundaryConfigured()
  1656. {
  1657. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1658. return false;
  1659. #else
  1660. if (version >= OVRP_1_8_0.version)
  1661. {
  1662. return OVRP_1_8_0.ovrp_GetBoundaryConfigured() == OVRPlugin.Bool.True;
  1663. }
  1664. else
  1665. {
  1666. return false;
  1667. }
  1668. #endif
  1669. }
  1670. public static BoundaryTestResult TestBoundaryNode(Node nodeId, BoundaryType boundaryType)
  1671. {
  1672. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1673. return new BoundaryTestResult();
  1674. #else
  1675. if (version >= OVRP_1_8_0.version)
  1676. {
  1677. return OVRP_1_8_0.ovrp_TestBoundaryNode(nodeId, boundaryType);
  1678. }
  1679. else
  1680. {
  1681. return new BoundaryTestResult();
  1682. }
  1683. #endif
  1684. }
  1685. public static BoundaryTestResult TestBoundaryPoint(Vector3f point, BoundaryType boundaryType)
  1686. {
  1687. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1688. return new BoundaryTestResult();
  1689. #else
  1690. if (version >= OVRP_1_8_0.version)
  1691. {
  1692. return OVRP_1_8_0.ovrp_TestBoundaryPoint(point, boundaryType);
  1693. }
  1694. else
  1695. {
  1696. return new BoundaryTestResult();
  1697. }
  1698. #endif
  1699. }
  1700. public static bool SetBoundaryLookAndFeel(BoundaryLookAndFeel lookAndFeel)
  1701. {
  1702. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1703. return false;
  1704. #else
  1705. if (version >= OVRP_1_8_0.version)
  1706. {
  1707. return OVRP_1_8_0.ovrp_SetBoundaryLookAndFeel(lookAndFeel) == OVRPlugin.Bool.True;
  1708. }
  1709. else
  1710. {
  1711. return false;
  1712. }
  1713. #endif
  1714. }
  1715. public static bool ResetBoundaryLookAndFeel()
  1716. {
  1717. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1718. return false;
  1719. #else
  1720. if (version >= OVRP_1_8_0.version)
  1721. {
  1722. return OVRP_1_8_0.ovrp_ResetBoundaryLookAndFeel() == OVRPlugin.Bool.True;
  1723. }
  1724. else
  1725. {
  1726. return false;
  1727. }
  1728. #endif
  1729. }
  1730. public static BoundaryGeometry GetBoundaryGeometry(BoundaryType boundaryType)
  1731. {
  1732. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1733. return new BoundaryGeometry();
  1734. #else
  1735. if (version >= OVRP_1_8_0.version)
  1736. {
  1737. return OVRP_1_8_0.ovrp_GetBoundaryGeometry(boundaryType);
  1738. }
  1739. else
  1740. {
  1741. return new BoundaryGeometry();
  1742. }
  1743. #endif
  1744. }
  1745. public static bool GetBoundaryGeometry2(BoundaryType boundaryType, IntPtr points, ref int pointsCount)
  1746. {
  1747. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1748. pointsCount = 0;
  1749. return false;
  1750. #else
  1751. if (version >= OVRP_1_9_0.version)
  1752. {
  1753. return OVRP_1_9_0.ovrp_GetBoundaryGeometry2(boundaryType, points, ref pointsCount) == OVRPlugin.Bool.True;
  1754. }
  1755. else
  1756. {
  1757. pointsCount = 0;
  1758. return false;
  1759. }
  1760. #endif
  1761. }
  1762. public static AppPerfStats GetAppPerfStats()
  1763. {
  1764. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1765. return new AppPerfStats();
  1766. #else
  1767. if (version >= OVRP_1_9_0.version)
  1768. {
  1769. return OVRP_1_9_0.ovrp_GetAppPerfStats();
  1770. }
  1771. else
  1772. {
  1773. return new AppPerfStats();
  1774. }
  1775. #endif
  1776. }
  1777. public static bool ResetAppPerfStats()
  1778. {
  1779. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1780. return false;
  1781. #else
  1782. if (version >= OVRP_1_9_0.version)
  1783. {
  1784. return OVRP_1_9_0.ovrp_ResetAppPerfStats() == OVRPlugin.Bool.True;
  1785. }
  1786. else
  1787. {
  1788. return false;
  1789. }
  1790. #endif
  1791. }
  1792. public static float GetAppFramerate()
  1793. {
  1794. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1795. return 0.0f;
  1796. #else
  1797. if (version >= OVRP_1_12_0.version)
  1798. {
  1799. return OVRP_1_12_0.ovrp_GetAppFramerate();
  1800. }
  1801. else
  1802. {
  1803. return 0.0f;
  1804. }
  1805. #endif
  1806. }
  1807. public static bool SetHandNodePoseStateLatency(double latencyInSeconds)
  1808. {
  1809. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1810. return false;
  1811. #else
  1812. if (version >= OVRP_1_18_0.version)
  1813. {
  1814. Result result = OVRP_1_18_0.ovrp_SetHandNodePoseStateLatency(latencyInSeconds);
  1815. if (result == Result.Success)
  1816. {
  1817. return true;
  1818. }
  1819. else
  1820. {
  1821. //Debug.LogWarning("ovrp_SetHandNodePoseStateLatency return " + result);
  1822. return false;
  1823. }
  1824. }
  1825. else
  1826. {
  1827. return false;
  1828. }
  1829. #endif
  1830. }
  1831. public static double GetHandNodePoseStateLatency()
  1832. {
  1833. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1834. return 0.0;
  1835. #else
  1836. if (version >= OVRP_1_18_0.version)
  1837. {
  1838. double value = 0.0;
  1839. if (OVRP_1_18_0.ovrp_GetHandNodePoseStateLatency(out value) == OVRPlugin.Result.Success)
  1840. {
  1841. return value;
  1842. }
  1843. else
  1844. {
  1845. return 0.0;
  1846. }
  1847. }
  1848. else
  1849. {
  1850. return 0.0;
  1851. }
  1852. #endif
  1853. }
  1854. public static EyeTextureFormat GetDesiredEyeTextureFormat()
  1855. {
  1856. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1857. return EyeTextureFormat.Default;
  1858. #else
  1859. if (version >= OVRP_1_11_0.version)
  1860. {
  1861. uint eyeTextureFormatValue = (uint)OVRP_1_11_0.ovrp_GetDesiredEyeTextureFormat();
  1862. // convert both R8G8B8A8 and R8G8B8A8_SRGB to R8G8B8A8 here for avoid confusing developers
  1863. if (eyeTextureFormatValue == 1)
  1864. eyeTextureFormatValue = 0;
  1865. return (EyeTextureFormat)eyeTextureFormatValue;
  1866. }
  1867. else
  1868. {
  1869. return EyeTextureFormat.Default;
  1870. }
  1871. #endif
  1872. }
  1873. public static bool SetDesiredEyeTextureFormat(EyeTextureFormat value)
  1874. {
  1875. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1876. return false;
  1877. #else
  1878. if (version >= OVRP_1_11_0.version)
  1879. {
  1880. return OVRP_1_11_0.ovrp_SetDesiredEyeTextureFormat(value) == OVRPlugin.Bool.True;
  1881. }
  1882. else
  1883. {
  1884. return false;
  1885. }
  1886. #endif
  1887. }
  1888. public static bool InitializeMixedReality()
  1889. {
  1890. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1891. return false;
  1892. #else
  1893. if (version >= OVRP_1_15_0.version)
  1894. {
  1895. Result result = OVRP_1_15_0.ovrp_InitializeMixedReality();
  1896. if (result != Result.Success)
  1897. {
  1898. //Debug.LogWarning("ovrp_InitializeMixedReality return " + result);
  1899. }
  1900. return result == Result.Success;
  1901. }
  1902. else
  1903. {
  1904. return false;
  1905. }
  1906. #endif
  1907. }
  1908. public static bool ShutdownMixedReality()
  1909. {
  1910. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1911. return false;
  1912. #else
  1913. if (version >= OVRP_1_15_0.version)
  1914. {
  1915. Result result = OVRP_1_15_0.ovrp_ShutdownMixedReality();
  1916. if (result != Result.Success)
  1917. {
  1918. //Debug.LogWarning("ovrp_ShutdownMixedReality return " + result);
  1919. }
  1920. return result == Result.Success;
  1921. }
  1922. else
  1923. {
  1924. return false;
  1925. }
  1926. #endif
  1927. }
  1928. public static bool IsMixedRealityInitialized()
  1929. {
  1930. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1931. return false;
  1932. #else
  1933. if (version >= OVRP_1_15_0.version)
  1934. {
  1935. return OVRP_1_15_0.ovrp_GetMixedRealityInitialized() == Bool.True;
  1936. }
  1937. else
  1938. {
  1939. return false;
  1940. }
  1941. #endif
  1942. }
  1943. public static int GetExternalCameraCount()
  1944. {
  1945. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1946. return 0;
  1947. #else
  1948. if (version >= OVRP_1_15_0.version)
  1949. {
  1950. int cameraCount = 0;
  1951. Result result = OVRP_1_15_0.ovrp_GetExternalCameraCount(out cameraCount);
  1952. if (result != OVRPlugin.Result.Success)
  1953. {
  1954. //Debug.LogWarning("ovrp_GetExternalCameraCount return " + result);
  1955. return 0;
  1956. }
  1957. return cameraCount;
  1958. }
  1959. else
  1960. {
  1961. return 0;
  1962. }
  1963. #endif
  1964. }
  1965. public static bool UpdateExternalCamera()
  1966. {
  1967. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1968. return false;
  1969. #else
  1970. if (version >= OVRP_1_15_0.version)
  1971. {
  1972. Result result = OVRP_1_15_0.ovrp_UpdateExternalCamera();
  1973. if (result != Result.Success)
  1974. {
  1975. //Debug.LogWarning("ovrp_UpdateExternalCamera return " + result);
  1976. }
  1977. return result == Result.Success;
  1978. }
  1979. else
  1980. {
  1981. return false;
  1982. }
  1983. #endif
  1984. }
  1985. public static bool GetMixedRealityCameraInfo(int cameraId, out CameraExtrinsics cameraExtrinsics, out CameraIntrinsics cameraIntrinsics)
  1986. {
  1987. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  1988. cameraExtrinsics = default(CameraExtrinsics);
  1989. cameraIntrinsics = default(CameraIntrinsics);
  1990. return false;
  1991. #else
  1992. cameraExtrinsics = default(CameraExtrinsics);
  1993. cameraIntrinsics = default(CameraIntrinsics);
  1994. if (version >= OVRP_1_15_0.version)
  1995. {
  1996. bool retValue = true;
  1997. Result result = OVRP_1_15_0.ovrp_GetExternalCameraExtrinsics(cameraId, out cameraExtrinsics);
  1998. if (result != Result.Success)
  1999. {
  2000. retValue = false;
  2001. //Debug.LogWarning("ovrp_GetExternalCameraExtrinsics return " + result);
  2002. }
  2003. result = OVRP_1_15_0.ovrp_GetExternalCameraIntrinsics(cameraId, out cameraIntrinsics);
  2004. if (result != Result.Success)
  2005. {
  2006. retValue = false;
  2007. //Debug.LogWarning("ovrp_GetExternalCameraIntrinsics return " + result);
  2008. }
  2009. return retValue;
  2010. }
  2011. else
  2012. {
  2013. return false;
  2014. }
  2015. #endif
  2016. }
  2017. public static Vector3f GetBoundaryDimensions(BoundaryType boundaryType)
  2018. {
  2019. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2020. return new Vector3f();
  2021. #else
  2022. if (version >= OVRP_1_8_0.version)
  2023. {
  2024. return OVRP_1_8_0.ovrp_GetBoundaryDimensions(boundaryType);
  2025. }
  2026. else
  2027. {
  2028. return new Vector3f();
  2029. }
  2030. #endif
  2031. }
  2032. public static bool GetBoundaryVisible()
  2033. {
  2034. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2035. return false;
  2036. #else
  2037. if (version >= OVRP_1_8_0.version)
  2038. {
  2039. return OVRP_1_8_0.ovrp_GetBoundaryVisible() == OVRPlugin.Bool.True;
  2040. }
  2041. else
  2042. {
  2043. return false;
  2044. }
  2045. #endif
  2046. }
  2047. public static bool SetBoundaryVisible(bool value)
  2048. {
  2049. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2050. return false;
  2051. #else
  2052. if (version >= OVRP_1_8_0.version)
  2053. {
  2054. return OVRP_1_8_0.ovrp_SetBoundaryVisible(ToBool(value)) == OVRPlugin.Bool.True;
  2055. }
  2056. else
  2057. {
  2058. return false;
  2059. }
  2060. #endif
  2061. }
  2062. public static SystemHeadset GetSystemHeadsetType()
  2063. {
  2064. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2065. return SystemHeadset.None;
  2066. #else
  2067. if (version >= OVRP_1_9_0.version)
  2068. return OVRP_1_9_0.ovrp_GetSystemHeadsetType();
  2069. return SystemHeadset.None;
  2070. #endif
  2071. }
  2072. public static Controller GetActiveController()
  2073. {
  2074. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2075. return Controller.None;
  2076. #else
  2077. if (version >= OVRP_1_9_0.version)
  2078. return OVRP_1_9_0.ovrp_GetActiveController();
  2079. return Controller.None;
  2080. #endif
  2081. }
  2082. public static Controller GetConnectedControllers()
  2083. {
  2084. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2085. return Controller.None;
  2086. #else
  2087. if (version >= OVRP_1_9_0.version)
  2088. return OVRP_1_9_0.ovrp_GetConnectedControllers();
  2089. return Controller.None;
  2090. #endif
  2091. }
  2092. private static Bool ToBool(bool b)
  2093. {
  2094. return (b) ? OVRPlugin.Bool.True : OVRPlugin.Bool.False;
  2095. }
  2096. public static TrackingOrigin GetTrackingOriginType()
  2097. {
  2098. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2099. return default(TrackingOrigin);
  2100. #else
  2101. return OVRP_1_0_0.ovrp_GetTrackingOriginType();
  2102. #endif
  2103. }
  2104. public static bool SetTrackingOriginType(TrackingOrigin originType)
  2105. {
  2106. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2107. return false;
  2108. #else
  2109. return OVRP_1_0_0.ovrp_SetTrackingOriginType(originType) == Bool.True;
  2110. #endif
  2111. }
  2112. public static Posef GetTrackingCalibratedOrigin()
  2113. {
  2114. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2115. return Posef.identity;
  2116. #else
  2117. return OVRP_1_0_0.ovrp_GetTrackingCalibratedOrigin();
  2118. #endif
  2119. }
  2120. public static bool SetTrackingCalibratedOrigin()
  2121. {
  2122. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2123. return false;
  2124. #else
  2125. return OVRP_1_2_0.ovrpi_SetTrackingCalibratedOrigin() == Bool.True;
  2126. #endif
  2127. }
  2128. public static bool RecenterTrackingOrigin(RecenterFlags flags)
  2129. {
  2130. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2131. return false;
  2132. #else
  2133. return OVRP_1_0_0.ovrp_RecenterTrackingOrigin((uint)flags) == Bool.True;
  2134. #endif
  2135. }
  2136. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
  2137. public static bool UpdateCameraDevices()
  2138. {
  2139. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2140. return false;
  2141. #else
  2142. if (version >= OVRP_1_16_0.version)
  2143. {
  2144. Result result = OVRP_1_16_0.ovrp_UpdateCameraDevices();
  2145. if (result != Result.Success)
  2146. {
  2147. //Debug.LogWarning("ovrp_UpdateCameraDevices return " + result);
  2148. }
  2149. return result == Result.Success;
  2150. }
  2151. else
  2152. {
  2153. return false;
  2154. }
  2155. #endif
  2156. }
  2157. public static bool IsCameraDeviceAvailable(CameraDevice cameraDevice)
  2158. {
  2159. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2160. return false;
  2161. #else
  2162. if (version >= OVRP_1_16_0.version)
  2163. {
  2164. Bool result = OVRP_1_16_0.ovrp_IsCameraDeviceAvailable(cameraDevice);
  2165. return result == Bool.True;
  2166. }
  2167. else
  2168. {
  2169. return false;
  2170. }
  2171. #endif
  2172. }
  2173. public static bool SetCameraDevicePreferredColorFrameSize(CameraDevice cameraDevice, int width, int height)
  2174. {
  2175. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2176. return false;
  2177. #else
  2178. if (version >= OVRP_1_16_0.version)
  2179. {
  2180. Sizei size = new Sizei();
  2181. size.w = width;
  2182. size.h = height;
  2183. Result result = OVRP_1_16_0.ovrp_SetCameraDevicePreferredColorFrameSize(cameraDevice, size);
  2184. if (result != Result.Success)
  2185. {
  2186. //Debug.LogWarning("ovrp_SetCameraDevicePreferredColorFrameSize return " + result);
  2187. }
  2188. return result == Result.Success;
  2189. }
  2190. else
  2191. {
  2192. return false;
  2193. }
  2194. #endif
  2195. }
  2196. public static bool OpenCameraDevice(CameraDevice cameraDevice)
  2197. {
  2198. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2199. return false;
  2200. #else
  2201. if (version >= OVRP_1_16_0.version)
  2202. {
  2203. Result result = OVRP_1_16_0.ovrp_OpenCameraDevice(cameraDevice);
  2204. if (result != Result.Success)
  2205. {
  2206. //Debug.LogWarning("ovrp_OpenCameraDevice return " + result);
  2207. }
  2208. return result == Result.Success;
  2209. }
  2210. else
  2211. {
  2212. return false;
  2213. }
  2214. #endif
  2215. }
  2216. public static bool CloseCameraDevice(CameraDevice cameraDevice)
  2217. {
  2218. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2219. return false;
  2220. #else
  2221. if (version >= OVRP_1_16_0.version)
  2222. {
  2223. Result result = OVRP_1_16_0.ovrp_CloseCameraDevice(cameraDevice);
  2224. if (result != Result.Success)
  2225. {
  2226. //Debug.LogWarning("ovrp_OpenCameraDevice return " + result);
  2227. }
  2228. return result == Result.Success;
  2229. }
  2230. else
  2231. {
  2232. return false;
  2233. }
  2234. #endif
  2235. }
  2236. public static bool HasCameraDeviceOpened(CameraDevice cameraDevice)
  2237. {
  2238. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2239. return false;
  2240. #else
  2241. if (version >= OVRP_1_16_0.version)
  2242. {
  2243. Bool result = OVRP_1_16_0.ovrp_HasCameraDeviceOpened(cameraDevice);
  2244. return result == Bool.True;
  2245. }
  2246. else
  2247. {
  2248. return false;
  2249. }
  2250. #endif
  2251. }
  2252. public static bool IsCameraDeviceColorFrameAvailable(CameraDevice cameraDevice)
  2253. {
  2254. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2255. return false;
  2256. #else
  2257. if (version >= OVRP_1_16_0.version)
  2258. {
  2259. Bool result = OVRP_1_16_0.ovrp_IsCameraDeviceColorFrameAvailable(cameraDevice);
  2260. return result == Bool.True;
  2261. }
  2262. else
  2263. {
  2264. return false;
  2265. }
  2266. #endif
  2267. }
  2268. private static Texture2D cachedCameraFrameTexture = null;
  2269. public static Texture2D GetCameraDeviceColorFrameTexture(CameraDevice cameraDevice)
  2270. {
  2271. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2272. return null;
  2273. #else
  2274. if (version >= OVRP_1_16_0.version)
  2275. {
  2276. Sizei size = new Sizei();
  2277. Result result = OVRP_1_16_0.ovrp_GetCameraDeviceColorFrameSize(cameraDevice, out size);
  2278. if (result != Result.Success)
  2279. {
  2280. //Debug.LogWarning("ovrp_GetCameraDeviceColorFrameSize return " + result);
  2281. return null;
  2282. }
  2283. IntPtr pixels;
  2284. int rowPitch;
  2285. result = OVRP_1_16_0.ovrp_GetCameraDeviceColorFrameBgraPixels(cameraDevice, out pixels, out rowPitch);
  2286. if (result != Result.Success)
  2287. {
  2288. //Debug.LogWarning("ovrp_GetCameraDeviceColorFrameBgraPixels return " + result);
  2289. return null;
  2290. }
  2291. if (rowPitch != size.w * 4)
  2292. {
  2293. //Debug.LogWarning(string.Format("RowPitch mismatch, expected {0}, get {1}", size.w * 4, rowPitch));
  2294. return null;
  2295. }
  2296. if (!cachedCameraFrameTexture || cachedCameraFrameTexture.width != size.w || cachedCameraFrameTexture.height != size.h)
  2297. {
  2298. cachedCameraFrameTexture = new Texture2D(size.w, size.h, TextureFormat.BGRA32, false);
  2299. }
  2300. cachedCameraFrameTexture.LoadRawTextureData(pixels, rowPitch * size.h);
  2301. cachedCameraFrameTexture.Apply();
  2302. return cachedCameraFrameTexture;
  2303. }
  2304. else
  2305. {
  2306. return null;
  2307. }
  2308. #endif
  2309. }
  2310. public static bool DoesCameraDeviceSupportDepth(CameraDevice cameraDevice)
  2311. {
  2312. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2313. return false;
  2314. #else
  2315. if (version >= OVRP_1_17_0.version)
  2316. {
  2317. Bool supportDepth;
  2318. Result result = OVRP_1_17_0.ovrp_DoesCameraDeviceSupportDepth(cameraDevice, out supportDepth);
  2319. return result == Result.Success && supportDepth == Bool.True;
  2320. }
  2321. else
  2322. {
  2323. return false;
  2324. }
  2325. #endif
  2326. }
  2327. public static bool SetCameraDeviceDepthSensingMode(CameraDevice camera, CameraDeviceDepthSensingMode depthSensoringMode)
  2328. {
  2329. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2330. return false;
  2331. #else
  2332. if (version >= OVRP_1_17_0.version)
  2333. {
  2334. Result result = OVRP_1_17_0.ovrp_SetCameraDeviceDepthSensingMode(camera, depthSensoringMode);
  2335. return result == Result.Success;
  2336. }
  2337. else
  2338. {
  2339. return false;
  2340. }
  2341. #endif
  2342. }
  2343. public static bool SetCameraDevicePreferredDepthQuality(CameraDevice camera, CameraDeviceDepthQuality depthQuality)
  2344. {
  2345. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2346. return false;
  2347. #else
  2348. if (version >= OVRP_1_17_0.version)
  2349. {
  2350. Result result = OVRP_1_17_0.ovrp_SetCameraDevicePreferredDepthQuality(camera, depthQuality);
  2351. return result == Result.Success;
  2352. }
  2353. else
  2354. {
  2355. return false;
  2356. }
  2357. #endif
  2358. }
  2359. public static bool IsCameraDeviceDepthFrameAvailable(CameraDevice cameraDevice)
  2360. {
  2361. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2362. return false;
  2363. #else
  2364. if (version >= OVRP_1_17_0.version)
  2365. {
  2366. Bool available;
  2367. Result result = OVRP_1_17_0.ovrp_IsCameraDeviceDepthFrameAvailable(cameraDevice, out available);
  2368. return result == Result.Success && available == Bool.True;
  2369. }
  2370. else
  2371. {
  2372. return false;
  2373. }
  2374. #endif
  2375. }
  2376. private static Texture2D cachedCameraDepthTexture = null;
  2377. public static Texture2D GetCameraDeviceDepthFrameTexture(CameraDevice cameraDevice)
  2378. {
  2379. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2380. return null;
  2381. #else
  2382. if (version >= OVRP_1_17_0.version)
  2383. {
  2384. Sizei size = new Sizei();
  2385. Result result = OVRP_1_17_0.ovrp_GetCameraDeviceDepthFrameSize(cameraDevice, out size);
  2386. if (result != Result.Success)
  2387. {
  2388. //Debug.LogWarning("ovrp_GetCameraDeviceDepthFrameSize return " + result);
  2389. return null;
  2390. }
  2391. IntPtr depthData;
  2392. int rowPitch;
  2393. result = OVRP_1_17_0.ovrp_GetCameraDeviceDepthFramePixels(cameraDevice, out depthData, out rowPitch);
  2394. if (result != Result.Success)
  2395. {
  2396. //Debug.LogWarning("ovrp_GetCameraDeviceDepthFramePixels return " + result);
  2397. return null;
  2398. }
  2399. if (rowPitch != size.w * 4)
  2400. {
  2401. //Debug.LogWarning(string.Format("RowPitch mismatch, expected {0}, get {1}", size.w * 4, rowPitch));
  2402. return null;
  2403. }
  2404. if (!cachedCameraDepthTexture || cachedCameraDepthTexture.width != size.w || cachedCameraDepthTexture.height != size.h)
  2405. {
  2406. cachedCameraDepthTexture = new Texture2D(size.w, size.h, TextureFormat.RFloat, false);
  2407. cachedCameraDepthTexture.filterMode = FilterMode.Point;
  2408. }
  2409. cachedCameraDepthTexture.LoadRawTextureData(depthData, rowPitch * size.h);
  2410. cachedCameraDepthTexture.Apply();
  2411. return cachedCameraDepthTexture;
  2412. }
  2413. else
  2414. {
  2415. return null;
  2416. }
  2417. #endif
  2418. }
  2419. private static Texture2D cachedCameraDepthConfidenceTexture = null;
  2420. public static Texture2D GetCameraDeviceDepthConfidenceTexture(CameraDevice cameraDevice)
  2421. {
  2422. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2423. return null;
  2424. #else
  2425. if (version >= OVRP_1_17_0.version)
  2426. {
  2427. Sizei size = new Sizei();
  2428. Result result = OVRP_1_17_0.ovrp_GetCameraDeviceDepthFrameSize(cameraDevice, out size);
  2429. if (result != Result.Success)
  2430. {
  2431. //Debug.LogWarning("ovrp_GetCameraDeviceDepthFrameSize return " + result);
  2432. return null;
  2433. }
  2434. IntPtr confidenceData;
  2435. int rowPitch;
  2436. result = OVRP_1_17_0.ovrp_GetCameraDeviceDepthConfidencePixels(cameraDevice, out confidenceData, out rowPitch);
  2437. if (result != Result.Success)
  2438. {
  2439. //Debug.LogWarning("ovrp_GetCameraDeviceDepthConfidencePixels return " + result);
  2440. return null;
  2441. }
  2442. if (rowPitch != size.w * 4)
  2443. {
  2444. //Debug.LogWarning(string.Format("RowPitch mismatch, expected {0}, get {1}", size.w * 4, rowPitch));
  2445. return null;
  2446. }
  2447. if (!cachedCameraDepthConfidenceTexture || cachedCameraDepthConfidenceTexture.width != size.w || cachedCameraDepthConfidenceTexture.height != size.h)
  2448. {
  2449. cachedCameraDepthConfidenceTexture = new Texture2D(size.w, size.h, TextureFormat.RFloat, false);
  2450. }
  2451. cachedCameraDepthConfidenceTexture.LoadRawTextureData(confidenceData, rowPitch * size.h);
  2452. cachedCameraDepthConfidenceTexture.Apply();
  2453. return cachedCameraDepthConfidenceTexture;
  2454. }
  2455. else
  2456. {
  2457. return null;
  2458. }
  2459. #endif
  2460. }
  2461. #endif
  2462. public static bool tiledMultiResSupported
  2463. {
  2464. get
  2465. {
  2466. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2467. return false;
  2468. #else
  2469. if (version >= OVRP_1_21_0.version)
  2470. {
  2471. Bool supported;
  2472. Result result = OVRP_1_21_0.ovrp_GetTiledMultiResSupported(out supported);
  2473. if (result == Result.Success)
  2474. {
  2475. return supported == Bool.True;
  2476. }
  2477. else
  2478. {
  2479. //Debug.LogWarning("ovrp_GetTiledMultiResSupported return " + result);
  2480. return false;
  2481. }
  2482. }
  2483. else
  2484. {
  2485. return false;
  2486. }
  2487. #endif
  2488. }
  2489. }
  2490. public static TiledMultiResLevel tiledMultiResLevel
  2491. {
  2492. get
  2493. {
  2494. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2495. return TiledMultiResLevel.Off;
  2496. #else
  2497. if (version >= OVRP_1_21_0.version && tiledMultiResSupported)
  2498. {
  2499. TiledMultiResLevel level;
  2500. Result result = OVRP_1_21_0.ovrp_GetTiledMultiResLevel(out level);
  2501. if (result != Result.Success)
  2502. {
  2503. //Debug.LogWarning("ovrp_GetTiledMultiResLevel return " + result);
  2504. }
  2505. return level;
  2506. }
  2507. else
  2508. {
  2509. return TiledMultiResLevel.Off;
  2510. }
  2511. #endif
  2512. }
  2513. set
  2514. {
  2515. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2516. return;
  2517. #else
  2518. if (version >= OVRP_1_21_0.version && tiledMultiResSupported)
  2519. {
  2520. Result result = OVRP_1_21_0.ovrp_SetTiledMultiResLevel(value);
  2521. if (result != Result.Success)
  2522. {
  2523. //Debug.LogWarning("ovrp_SetTiledMultiResLevel return " + result);
  2524. }
  2525. }
  2526. #endif
  2527. }
  2528. }
  2529. public static bool gpuUtilSupported
  2530. {
  2531. get
  2532. {
  2533. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2534. return false;
  2535. #else
  2536. if (version >= OVRP_1_21_0.version)
  2537. {
  2538. Bool supported;
  2539. Result result = OVRP_1_21_0.ovrp_GetGPUUtilSupported(out supported);
  2540. if (result == Result.Success)
  2541. {
  2542. return supported == Bool.True;
  2543. }
  2544. else
  2545. {
  2546. //Debug.LogWarning("ovrp_GetGPUUtilSupported return " + result);
  2547. return false;
  2548. }
  2549. }
  2550. else
  2551. {
  2552. return false;
  2553. }
  2554. #endif
  2555. }
  2556. }
  2557. public static float gpuUtilLevel
  2558. {
  2559. get
  2560. {
  2561. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2562. return 0.0f;
  2563. #else
  2564. if (version >= OVRP_1_21_0.version && gpuUtilSupported)
  2565. {
  2566. float level;
  2567. Result result = OVRP_1_21_0.ovrp_GetGPUUtilLevel(out level);
  2568. if (result == Result.Success)
  2569. {
  2570. return level;
  2571. }
  2572. else
  2573. {
  2574. //Debug.LogWarning("ovrp_GetGPUUtilLevel return " + result);
  2575. return 0.0f;
  2576. }
  2577. }
  2578. else
  2579. {
  2580. return 0.0f;
  2581. }
  2582. #endif
  2583. }
  2584. }
  2585. #if !OVRPLUGIN_UNSUPPORTED_PLATFORM
  2586. private static OVRNativeBuffer _nativeSystemDisplayFrequenciesAvailable = null;
  2587. private static float[] _cachedSystemDisplayFrequenciesAvailable = null;
  2588. #endif
  2589. public static float[] systemDisplayFrequenciesAvailable
  2590. {
  2591. get
  2592. {
  2593. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2594. return new float[0];
  2595. #else
  2596. if (_cachedSystemDisplayFrequenciesAvailable == null)
  2597. {
  2598. _cachedSystemDisplayFrequenciesAvailable = new float[0];
  2599. if (version >= OVRP_1_21_0.version)
  2600. {
  2601. int numFrequencies = 0;
  2602. Result result = OVRP_1_21_0.ovrp_GetSystemDisplayAvailableFrequencies(IntPtr.Zero, out numFrequencies);
  2603. if (result == Result.Success)
  2604. {
  2605. if (numFrequencies > 0)
  2606. {
  2607. int maxNumElements = numFrequencies;
  2608. _nativeSystemDisplayFrequenciesAvailable = new OVRNativeBuffer(sizeof(float) * maxNumElements);
  2609. result = OVRP_1_21_0.ovrp_GetSystemDisplayAvailableFrequencies(_nativeSystemDisplayFrequenciesAvailable.GetPointer(), out numFrequencies);
  2610. if (result == Result.Success)
  2611. {
  2612. int numElementsToCopy = (numFrequencies <= maxNumElements) ? numFrequencies : maxNumElements;
  2613. if (numElementsToCopy > 0)
  2614. {
  2615. _cachedSystemDisplayFrequenciesAvailable = new float[numElementsToCopy];
  2616. Marshal.Copy(_nativeSystemDisplayFrequenciesAvailable.GetPointer(), _cachedSystemDisplayFrequenciesAvailable, 0, numElementsToCopy);
  2617. }
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. return _cachedSystemDisplayFrequenciesAvailable;
  2624. #endif
  2625. }
  2626. }
  2627. public static float systemDisplayFrequency
  2628. {
  2629. get
  2630. {
  2631. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2632. return 0.0f;
  2633. #else
  2634. if (version >= OVRP_1_21_0.version)
  2635. {
  2636. float displayFrequency;
  2637. Result result = OVRP_1_21_0.ovrp_GetSystemDisplayFrequency2(out displayFrequency);
  2638. if (result == Result.Success)
  2639. {
  2640. return displayFrequency;
  2641. }
  2642. return 0.0f;
  2643. }
  2644. else if (version >= OVRP_1_1_0.version)
  2645. {
  2646. return OVRP_1_1_0.ovrp_GetSystemDisplayFrequency();
  2647. }
  2648. else
  2649. {
  2650. return 0.0f;
  2651. }
  2652. #endif
  2653. }
  2654. set
  2655. {
  2656. #if OVRPLUGIN_UNSUPPORTED_PLATFORM
  2657. return;
  2658. #else
  2659. if (version >= OVRP_1_21_0.version)
  2660. {
  2661. OVRP_1_21_0.ovrp_SetSystemDisplayFrequency(value);
  2662. }
  2663. #endif
  2664. }
  2665. }
  2666. public static bool GetNodeFrustum2(Node nodeId, out Frustumf2 frustum)
  2667. {
  2668. frustum = default(Frustumf2);
  2669. #if !OVRPLUGIN_UNSUPPORTED_PLATFORM
  2670. if (version >= OVRP_1_15_0.version)
  2671. {
  2672. Result result = OVRP_1_15_0.ovrp_GetNodeFrustum2(nodeId, out frustum);
  2673. if (result != Result.Success)
  2674. {
  2675. return false;
  2676. }
  2677. else
  2678. {
  2679. return true;
  2680. }
  2681. }
  2682. else
  2683. #endif
  2684. {
  2685. return false;
  2686. }
  2687. }
  2688. public static bool AsymmetricFovEnabled
  2689. {
  2690. get
  2691. {
  2692. #if !OVRPLUGIN_UNSUPPORTED_PLATFORM
  2693. if (version >= OVRP_1_21_0.version)
  2694. {
  2695. Bool asymmetricFovEnabled = Bool.False;
  2696. Result result = OVRP_1_21_0.ovrp_GetAppAsymmetricFov(out asymmetricFovEnabled);
  2697. if (result != Result.Success)
  2698. {
  2699. return false;
  2700. }
  2701. else
  2702. {
  2703. return asymmetricFovEnabled == Bool.True;
  2704. }
  2705. }
  2706. else
  2707. #endif
  2708. {
  2709. return false;
  2710. }
  2711. }
  2712. }
  2713. public static bool EyeTextureArrayEnabled
  2714. {
  2715. get
  2716. {
  2717. #if !OVRPLUGIN_UNSUPPORTED_PLATFORM
  2718. if (version >= OVRP_1_15_0.version)
  2719. {
  2720. Bool enabled = Bool.False;
  2721. enabled = OVRP_1_15_0.ovrp_GetEyeTextureArrayEnabled();
  2722. return enabled == Bool.True;
  2723. }
  2724. else
  2725. #endif
  2726. {
  2727. return false;
  2728. }
  2729. }
  2730. }
  2731. private const string pluginName = "OVRPlugin";
  2732. private static System.Version _versionZero = new System.Version(0, 0, 0);
  2733. // Disable all the DllImports when the platform is not supported
  2734. #if !OVRPLUGIN_UNSUPPORTED_PLATFORM
  2735. private static class OVRP_0_1_0
  2736. {
  2737. public static readonly System.Version version = new System.Version(0, 1, 0);
  2738. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2739. public static extern Sizei ovrp_GetEyeTextureSize(Eye eyeId);
  2740. }
  2741. private static class OVRP_0_1_1
  2742. {
  2743. public static readonly System.Version version = new System.Version(0, 1, 1);
  2744. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2745. public static extern Bool ovrp_SetOverlayQuad2(Bool onTop, Bool headLocked, IntPtr texture, IntPtr device, Posef pose, Vector3f scale);
  2746. }
  2747. private static class OVRP_0_1_2
  2748. {
  2749. public static readonly System.Version version = new System.Version(0, 1, 2);
  2750. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2751. public static extern Posef ovrp_GetNodePose(Node nodeId);
  2752. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2753. public static extern Bool ovrp_SetControllerVibration(uint controllerMask, float frequency, float amplitude);
  2754. }
  2755. private static class OVRP_0_1_3
  2756. {
  2757. public static readonly System.Version version = new System.Version(0, 1, 3);
  2758. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2759. public static extern Posef ovrp_GetNodeVelocity(Node nodeId);
  2760. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2761. public static extern Posef ovrp_GetNodeAcceleration(Node nodeId);
  2762. }
  2763. private static class OVRP_0_5_0
  2764. {
  2765. public static readonly System.Version version = new System.Version(0, 5, 0);
  2766. }
  2767. private static class OVRP_1_0_0
  2768. {
  2769. public static readonly System.Version version = new System.Version(1, 0, 0);
  2770. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2771. public static extern TrackingOrigin ovrp_GetTrackingOriginType();
  2772. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2773. public static extern Bool ovrp_SetTrackingOriginType(TrackingOrigin originType);
  2774. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2775. public static extern Posef ovrp_GetTrackingCalibratedOrigin();
  2776. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2777. public static extern Bool ovrp_RecenterTrackingOrigin(uint flags);
  2778. }
  2779. private static class OVRP_1_1_0
  2780. {
  2781. public static readonly System.Version version = new System.Version(1, 1, 0);
  2782. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2783. public static extern Bool ovrp_GetInitialized();
  2784. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrp_GetVersion")]
  2785. private static extern IntPtr _ovrp_GetVersion();
  2786. public static string ovrp_GetVersion() { return Marshal.PtrToStringAnsi(_ovrp_GetVersion()); }
  2787. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrp_GetNativeSDKVersion")]
  2788. private static extern IntPtr _ovrp_GetNativeSDKVersion();
  2789. public static string ovrp_GetNativeSDKVersion() { return Marshal.PtrToStringAnsi(_ovrp_GetNativeSDKVersion()); }
  2790. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2791. public static extern IntPtr ovrp_GetAudioOutId();
  2792. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2793. public static extern IntPtr ovrp_GetAudioInId();
  2794. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2795. public static extern float ovrp_GetEyeTextureScale();
  2796. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2797. public static extern Bool ovrp_SetEyeTextureScale(float value);
  2798. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2799. public static extern Bool ovrp_GetTrackingOrientationSupported();
  2800. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2801. public static extern Bool ovrp_GetTrackingOrientationEnabled();
  2802. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2803. public static extern Bool ovrp_SetTrackingOrientationEnabled(Bool value);
  2804. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2805. public static extern Bool ovrp_GetTrackingPositionSupported();
  2806. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2807. public static extern Bool ovrp_GetTrackingPositionEnabled();
  2808. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2809. public static extern Bool ovrp_SetTrackingPositionEnabled(Bool value);
  2810. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2811. public static extern Bool ovrp_GetNodePresent(Node nodeId);
  2812. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2813. public static extern Bool ovrp_GetNodeOrientationTracked(Node nodeId);
  2814. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2815. public static extern Bool ovrp_GetNodePositionTracked(Node nodeId);
  2816. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2817. public static extern Frustumf ovrp_GetNodeFrustum(Node nodeId);
  2818. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2819. public static extern ControllerState ovrp_GetControllerState(uint controllerMask);
  2820. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2821. public static extern int ovrp_GetSystemCpuLevel();
  2822. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2823. public static extern Bool ovrp_SetSystemCpuLevel(int value);
  2824. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2825. public static extern int ovrp_GetSystemGpuLevel();
  2826. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2827. public static extern Bool ovrp_SetSystemGpuLevel(int value);
  2828. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2829. public static extern Bool ovrp_GetSystemPowerSavingMode();
  2830. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2831. public static extern float ovrp_GetSystemDisplayFrequency();
  2832. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2833. public static extern int ovrp_GetSystemVSyncCount();
  2834. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2835. public static extern float ovrp_GetSystemVolume();
  2836. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2837. public static extern BatteryStatus ovrp_GetSystemBatteryStatus();
  2838. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2839. public static extern float ovrp_GetSystemBatteryLevel();
  2840. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2841. public static extern float ovrp_GetSystemBatteryTemperature();
  2842. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrp_GetSystemProductName")]
  2843. private static extern IntPtr _ovrp_GetSystemProductName();
  2844. public static string ovrp_GetSystemProductName() { return Marshal.PtrToStringAnsi(_ovrp_GetSystemProductName()); }
  2845. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2846. public static extern Bool ovrp_ShowSystemUI(PlatformUI ui);
  2847. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2848. public static extern Bool ovrp_GetAppMonoscopic();
  2849. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2850. public static extern Bool ovrp_SetAppMonoscopic(Bool value);
  2851. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2852. public static extern Bool ovrp_GetAppHasVrFocus();
  2853. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2854. public static extern Bool ovrp_GetAppShouldQuit();
  2855. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2856. public static extern Bool ovrp_GetAppShouldRecenter();
  2857. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrp_GetAppLatencyTimings")]
  2858. private static extern IntPtr _ovrp_GetAppLatencyTimings();
  2859. public static string ovrp_GetAppLatencyTimings() { return Marshal.PtrToStringAnsi(_ovrp_GetAppLatencyTimings()); }
  2860. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2861. public static extern Bool ovrp_GetUserPresent();
  2862. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2863. public static extern float ovrp_GetUserIPD();
  2864. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2865. public static extern Bool ovrp_SetUserIPD(float value);
  2866. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2867. public static extern float ovrp_GetUserEyeDepth();
  2868. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2869. public static extern Bool ovrp_SetUserEyeDepth(float value);
  2870. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2871. public static extern float ovrp_GetUserEyeHeight();
  2872. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2873. public static extern Bool ovrp_SetUserEyeHeight(float value);
  2874. }
  2875. private static class OVRP_1_2_0
  2876. {
  2877. public static readonly System.Version version = new System.Version(1, 2, 0);
  2878. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2879. public static extern Bool ovrp_SetSystemVSyncCount(int vsyncCount);
  2880. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2881. public static extern Bool ovrpi_SetTrackingCalibratedOrigin();
  2882. }
  2883. private static class OVRP_1_3_0
  2884. {
  2885. public static readonly System.Version version = new System.Version(1, 3, 0);
  2886. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2887. public static extern Bool ovrp_GetEyeOcclusionMeshEnabled();
  2888. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2889. public static extern Bool ovrp_SetEyeOcclusionMeshEnabled(Bool value);
  2890. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2891. public static extern Bool ovrp_GetSystemHeadphonesPresent();
  2892. }
  2893. private static class OVRP_1_5_0
  2894. {
  2895. public static readonly System.Version version = new System.Version(1, 5, 0);
  2896. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2897. public static extern SystemRegion ovrp_GetSystemRegion();
  2898. }
  2899. private static class OVRP_1_6_0
  2900. {
  2901. public static readonly System.Version version = new System.Version(1, 6, 0);
  2902. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2903. public static extern Bool ovrp_GetTrackingIPDEnabled();
  2904. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2905. public static extern Bool ovrp_SetTrackingIPDEnabled(Bool value);
  2906. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2907. public static extern HapticsDesc ovrp_GetControllerHapticsDesc(uint controllerMask);
  2908. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2909. public static extern HapticsState ovrp_GetControllerHapticsState(uint controllerMask);
  2910. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2911. public static extern Bool ovrp_SetControllerHaptics(uint controllerMask, HapticsBuffer hapticsBuffer);
  2912. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2913. public static extern Bool ovrp_SetOverlayQuad3(uint flags, IntPtr textureLeft, IntPtr textureRight, IntPtr device, Posef pose, Vector3f scale, int layerIndex);
  2914. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2915. public static extern float ovrp_GetEyeRecommendedResolutionScale();
  2916. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2917. public static extern float ovrp_GetAppCpuStartToGpuEndTime();
  2918. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2919. public static extern int ovrp_GetSystemRecommendedMSAALevel();
  2920. }
  2921. private static class OVRP_1_7_0
  2922. {
  2923. public static readonly System.Version version = new System.Version(1, 7, 0);
  2924. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2925. public static extern Bool ovrp_GetAppChromaticCorrection();
  2926. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2927. public static extern Bool ovrp_SetAppChromaticCorrection(Bool value);
  2928. }
  2929. private static class OVRP_1_8_0
  2930. {
  2931. public static readonly System.Version version = new System.Version(1, 8, 0);
  2932. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2933. public static extern Bool ovrp_GetBoundaryConfigured();
  2934. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2935. public static extern BoundaryTestResult ovrp_TestBoundaryNode(Node nodeId, BoundaryType boundaryType);
  2936. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2937. public static extern BoundaryTestResult ovrp_TestBoundaryPoint(Vector3f point, BoundaryType boundaryType);
  2938. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2939. public static extern Bool ovrp_SetBoundaryLookAndFeel(BoundaryLookAndFeel lookAndFeel);
  2940. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2941. public static extern Bool ovrp_ResetBoundaryLookAndFeel();
  2942. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2943. public static extern BoundaryGeometry ovrp_GetBoundaryGeometry(BoundaryType boundaryType);
  2944. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2945. public static extern Vector3f ovrp_GetBoundaryDimensions(BoundaryType boundaryType);
  2946. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2947. public static extern Bool ovrp_GetBoundaryVisible();
  2948. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2949. public static extern Bool ovrp_SetBoundaryVisible(Bool value);
  2950. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2951. public static extern Bool ovrp_Update2(int stateId, int frameIndex, double predictionSeconds);
  2952. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2953. public static extern Posef ovrp_GetNodePose2(int stateId, Node nodeId);
  2954. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2955. public static extern Posef ovrp_GetNodeVelocity2(int stateId, Node nodeId);
  2956. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2957. public static extern Posef ovrp_GetNodeAcceleration2(int stateId, Node nodeId);
  2958. }
  2959. private static class OVRP_1_9_0
  2960. {
  2961. public static readonly System.Version version = new System.Version(1, 9, 0);
  2962. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2963. public static extern SystemHeadset ovrp_GetSystemHeadsetType();
  2964. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2965. public static extern Controller ovrp_GetActiveController();
  2966. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2967. public static extern Controller ovrp_GetConnectedControllers();
  2968. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2969. public static extern Bool ovrp_GetBoundaryGeometry2(BoundaryType boundaryType, IntPtr points, ref int pointsCount);
  2970. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2971. public static extern AppPerfStats ovrp_GetAppPerfStats();
  2972. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2973. public static extern Bool ovrp_ResetAppPerfStats();
  2974. }
  2975. private static class OVRP_1_10_0
  2976. {
  2977. public static readonly System.Version version = new System.Version(1, 10, 0);
  2978. }
  2979. private static class OVRP_1_11_0
  2980. {
  2981. public static readonly System.Version version = new System.Version(1, 11, 0);
  2982. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2983. public static extern Bool ovrp_SetDesiredEyeTextureFormat(EyeTextureFormat value);
  2984. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2985. public static extern EyeTextureFormat ovrp_GetDesiredEyeTextureFormat();
  2986. }
  2987. private static class OVRP_1_12_0
  2988. {
  2989. public static readonly System.Version version = new System.Version(1, 12, 0);
  2990. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2991. public static extern float ovrp_GetAppFramerate();
  2992. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2993. public static extern PoseStatef ovrp_GetNodePoseState(Step stepId, Node nodeId);
  2994. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  2995. public static extern ControllerState2 ovrp_GetControllerState2(uint controllerMask);
  2996. }
  2997. private static class OVRP_1_15_0
  2998. {
  2999. public const int OVRP_EXTERNAL_CAMERA_NAME_SIZE = 32;
  3000. public static readonly System.Version version = new System.Version(1, 15, 0);
  3001. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3002. public static extern Result ovrp_InitializeMixedReality();
  3003. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3004. public static extern Result ovrp_ShutdownMixedReality();
  3005. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3006. public static extern Bool ovrp_GetMixedRealityInitialized();
  3007. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3008. public static extern Result ovrp_UpdateExternalCamera();
  3009. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3010. public static extern Result ovrp_GetExternalCameraCount(out int cameraCount);
  3011. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3012. public static extern Result ovrp_GetExternalCameraName(int cameraId, [MarshalAs(UnmanagedType.LPArray, SizeConst = OVRP_EXTERNAL_CAMERA_NAME_SIZE)] char[] cameraName);
  3013. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3014. public static extern Result ovrp_GetExternalCameraIntrinsics(int cameraId, out CameraIntrinsics cameraIntrinsics);
  3015. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3016. public static extern Result ovrp_GetExternalCameraExtrinsics(int cameraId, out CameraExtrinsics cameraExtrinsics);
  3017. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3018. public static extern Result ovrp_CalculateLayerDesc(OverlayShape shape, LayerLayout layout, ref Sizei textureSize,
  3019. int mipLevels, int sampleCount, EyeTextureFormat format, int layerFlags, ref LayerDesc layerDesc);
  3020. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3021. public static extern Result ovrp_EnqueueSetupLayer(ref LayerDesc desc, IntPtr layerId);
  3022. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3023. public static extern Result ovrp_EnqueueDestroyLayer(IntPtr layerId);
  3024. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3025. public static extern Result ovrp_GetLayerTextureStageCount(int layerId, ref int layerTextureStageCount);
  3026. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3027. public static extern Result ovrp_GetLayerTexturePtr(int layerId, int stage, Eye eyeId, ref IntPtr textureHandle);
  3028. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3029. public static extern Result ovrp_EnqueueSubmitLayer(uint flags, IntPtr textureLeft, IntPtr textureRight, int layerId, int frameIndex, ref Posef pose, ref Vector3f scale, int layerIndex);
  3030. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3031. public static extern Result ovrp_GetNodeFrustum2(Node nodeId, out Frustumf2 nodeFrustum);
  3032. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3033. public static extern Bool ovrp_GetEyeTextureArrayEnabled();
  3034. }
  3035. private static class OVRP_1_16_0
  3036. {
  3037. public static readonly System.Version version = new System.Version(1, 16, 0);
  3038. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
  3039. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3040. public static extern Result ovrp_UpdateCameraDevices();
  3041. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3042. public static extern Bool ovrp_IsCameraDeviceAvailable(CameraDevice cameraDevice);
  3043. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3044. public static extern Result ovrp_SetCameraDevicePreferredColorFrameSize(CameraDevice cameraDevice, Sizei preferredColorFrameSize);
  3045. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3046. public static extern Result ovrp_OpenCameraDevice(CameraDevice cameraDevice);
  3047. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3048. public static extern Result ovrp_CloseCameraDevice(CameraDevice cameraDevice);
  3049. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3050. public static extern Bool ovrp_HasCameraDeviceOpened(CameraDevice cameraDevice);
  3051. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3052. public static extern Bool ovrp_IsCameraDeviceColorFrameAvailable(CameraDevice cameraDevice);
  3053. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3054. public static extern Result ovrp_GetCameraDeviceColorFrameSize(CameraDevice cameraDevice, out Sizei colorFrameSize);
  3055. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3056. public static extern Result ovrp_GetCameraDeviceColorFrameBgraPixels(CameraDevice cameraDevice, out IntPtr colorFrameBgraPixels, out int colorFrameRowPitch);
  3057. #endif
  3058. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3059. public static extern Result ovrp_GetControllerState4(uint controllerMask, ref ControllerState4 controllerState);
  3060. }
  3061. private static class OVRP_1_17_0
  3062. {
  3063. public static readonly System.Version version = new System.Version(1, 17, 0);
  3064. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
  3065. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3066. public static extern Result ovrp_GetExternalCameraPose(CameraDevice camera, out Posef cameraPose);
  3067. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3068. public static extern Result ovrp_ConvertPoseToCameraSpace(CameraDevice camera, ref Posef trackingSpacePose, out Posef cameraSpacePose);
  3069. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3070. public static extern Result ovrp_GetCameraDeviceIntrinsicsParameters(CameraDevice camera, out Bool supportIntrinsics, out CameraDeviceIntrinsicsParameters intrinsicsParameters);
  3071. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3072. public static extern Result ovrp_DoesCameraDeviceSupportDepth(CameraDevice camera, out Bool supportDepth);
  3073. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3074. public static extern Result ovrp_GetCameraDeviceDepthSensingMode(CameraDevice camera, out CameraDeviceDepthSensingMode depthSensoringMode);
  3075. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3076. public static extern Result ovrp_SetCameraDeviceDepthSensingMode(CameraDevice camera, CameraDeviceDepthSensingMode depthSensoringMode);
  3077. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3078. public static extern Result ovrp_GetCameraDevicePreferredDepthQuality(CameraDevice camera, out CameraDeviceDepthQuality depthQuality);
  3079. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3080. public static extern Result ovrp_SetCameraDevicePreferredDepthQuality(CameraDevice camera, CameraDeviceDepthQuality depthQuality);
  3081. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3082. public static extern Result ovrp_IsCameraDeviceDepthFrameAvailable(CameraDevice camera, out Bool available);
  3083. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3084. public static extern Result ovrp_GetCameraDeviceDepthFrameSize(CameraDevice camera, out Sizei depthFrameSize);
  3085. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3086. public static extern Result ovrp_GetCameraDeviceDepthFramePixels(CameraDevice cameraDevice, out IntPtr depthFramePixels, out int depthFrameRowPitch);
  3087. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3088. public static extern Result ovrp_GetCameraDeviceDepthConfidencePixels(CameraDevice cameraDevice, out IntPtr depthConfidencePixels, out int depthConfidenceRowPitch);
  3089. #endif
  3090. }
  3091. private static class OVRP_1_18_0
  3092. {
  3093. public static readonly System.Version version = new System.Version(1, 18, 0);
  3094. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3095. public static extern Result ovrp_SetHandNodePoseStateLatency(double latencyInSeconds);
  3096. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3097. public static extern Result ovrp_GetHandNodePoseStateLatency(out double latencyInSeconds);
  3098. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3099. public static extern Result ovrp_GetAppHasInputFocus(out Bool appHasInputFocus);
  3100. }
  3101. private static class OVRP_1_19_0
  3102. {
  3103. public static readonly System.Version version = new System.Version(1, 19, 0);
  3104. }
  3105. private static class OVRP_1_21_0
  3106. {
  3107. public static readonly System.Version version = new System.Version(1, 21, 0);
  3108. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3109. public static extern Result ovrp_GetTiledMultiResSupported(out Bool foveationSupported);
  3110. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3111. public static extern Result ovrp_GetTiledMultiResLevel(out TiledMultiResLevel level);
  3112. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3113. public static extern Result ovrp_SetTiledMultiResLevel(TiledMultiResLevel level);
  3114. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3115. public static extern Result ovrp_GetGPUUtilSupported(out Bool gpuUtilSupported);
  3116. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3117. public static extern Result ovrp_GetGPUUtilLevel(out float gpuUtil);
  3118. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3119. public static extern Result ovrp_GetSystemDisplayFrequency2(out float systemDisplayFrequency);
  3120. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3121. public static extern Result ovrp_GetSystemDisplayAvailableFrequencies(IntPtr systemDisplayAvailableFrequencies, out int numFrequencies);
  3122. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3123. public static extern Result ovrp_SetSystemDisplayFrequency(float requestedFrequency);
  3124. [DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
  3125. public static extern Result ovrp_GetAppAsymmetricFov(out Bool useAsymmetricFov);
  3126. }
  3127. private static class OVRP_1_27_0
  3128. {
  3129. public static readonly System.Version version = new System.Version(1, 27, 0);
  3130. }
  3131. #endif // !OVRPLUGIN_UNSUPPORTED_PLATFORM
  3132. }