ovr_sdk
view LibOVR/Src/CAPI/CAPI_HMDState.h @ 3:f12a8f74fe1f
added the Xcode project
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 21 Jan 2015 11:37:50 +0200 |
parents | |
children |
line source
1 /************************************************************************************
3 Filename : CAPI_HMDState.h
4 Content : State associated with a single HMD
5 Created : January 24, 2014
6 Authors : Michael Antonov
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 You may obtain a copy of the License at
17 http://www.oculusvr.com/licenses/LICENSE-3.2
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
25 ************************************************************************************/
27 #ifndef OVR_CAPI_HMDState_h
28 #define OVR_CAPI_HMDState_h
30 #include "../Kernel/OVR_Math.h"
31 #include "../Kernel/OVR_List.h"
32 #include "../Kernel/OVR_Log.h"
33 #include "../OVR_CAPI.h"
35 #include "CAPI_FrameTimeManager.h"
36 #include "CAPI_LatencyStatistics.h"
37 #include "CAPI_HMDRenderState.h"
38 #include "CAPI_DistortionRenderer.h"
39 #include "CAPI_HSWDisplay.h"
41 #include "../Service/Service_NetClient.h"
42 #include "../Net/OVR_NetworkTypes.h"
43 #include "../Util/Util_LatencyTest2Reader.h"
45 struct ovrHmdStruct { };
47 namespace OVR { namespace CAPI {
50 using namespace OVR::Util::Render;
51 using namespace OVR::Service;
52 using namespace OVR::Net;
55 //-------------------------------------------------------------------------------------
56 // ***** ThreadChecker
58 // This helper class is used to verify that the API is used according to supported
59 // thread safety constraints (is not re-entrant for this and related functions).
60 class ThreadChecker
61 {
62 public:
64 #ifndef OVR_BUILD_DEBUG
66 // In release build, thread checks are disabled.
67 ThreadChecker() { }
68 void Begin(const char* functionName) { OVR_UNUSED1(functionName); }
69 void End() { }
71 // Add thread-re-entrancy check for function scope
72 struct Scope
73 {
74 Scope(ThreadChecker*, const char *) { }
75 ~Scope() { }
76 };
79 #else // OVR_BUILD_DEBUG
80 ThreadChecker() : pFunctionName(0), FirstThread(0)
81 { }
83 void Begin(const char* functionName)
84 {
85 if (!pFunctionName)
86 {
87 pFunctionName = functionName;
88 FirstThread = GetCurrentThreadId();
89 }
90 else
91 {
92 // pFunctionName may be not null here if function is called internally on the same thread.
93 OVR_ASSERT_LOG((FirstThread == GetCurrentThreadId()),
94 ("%s (threadId=%p) called at the same times as %s (threadId=%p)\n",
95 functionName, GetCurrentThreadId(), pFunctionName, FirstThread) );
96 }
97 }
98 void End()
99 {
100 pFunctionName = 0;
101 FirstThread = 0;
102 }
104 // Add thread-reentrancy check for function scope.
105 struct Scope
106 {
107 Scope(ThreadChecker* threadChecker, const char *functionName) : pChecker(threadChecker)
108 { pChecker->Begin(functionName); }
109 ~Scope()
110 { pChecker->End(); }
111 private:
112 ThreadChecker* pChecker;
113 };
115 private:
116 // If not 0, contains the name of the function that first entered the scope.
117 const char * pFunctionName;
118 ThreadId FirstThread;
120 #endif // OVR_BUILD_DEBUG
121 };
124 //-------------------------------------------------------------------------------------
125 // ***** HMDState
127 // Describes a single HMD.
128 class HMDState : public ListNode<HMDState>,
129 public ovrHmdStruct, public NewOverrideBase
130 {
131 void operator=(const HMDState&) { } // Quiet warning.
133 protected:
134 HMDState(const OVR::Service::HMDNetworkInfo& netInfo,
135 const OVR::HMDInfo& hmdInfo,
136 Profile* profile,
137 Service::NetClient* client);
138 HMDState(const HMDInfo& src, Profile* profile);
140 public:
141 virtual ~HMDState();
143 static HMDState* CreateHMDState(Service::NetClient* client, const HMDNetworkInfo& netInfo);
144 static HMDState* CreateHMDState(ovrHmdType hmdType); // Used for debug mode
145 static const OVR::List<HMDState>& GetHMDStateList();
147 // *** Sensor Setup
149 bool ConfigureTracking(unsigned supportedCaps, unsigned requiredCaps);
150 void ResetTracking();
151 void RecenterPose();
152 ovrTrackingState PredictedTrackingState(double absTime);
154 // Changes HMD Caps.
155 // Capability bits that are not directly or logically tied to one system (such as sensor)
156 // are grouped here. ovrHmdCap_VSync, for example, affects rendering and timing.
157 void SetEnabledHmdCaps(unsigned caps);
158 unsigned SetEnabledHmdCaps();
160 bool ProcessLatencyTest(unsigned char rgbColorOut[3]);
162 // *** Rendering Setup
163 bool ConfigureRendering(ovrEyeRenderDesc eyeRenderDescOut[2],
164 const ovrFovPort eyeFovIn[2],
165 const ovrRenderAPIConfig* apiConfig,
166 unsigned distortionCaps);
168 void UpdateRenderProfile(Profile* profile);
171 void SubmitEyeTextures(const ovrPosef renderPose[2],
172 const ovrTexture eyeTexture[2]);
175 void sharedInit ( Profile *profile );
177 void applyProfileToSensorFusion();
179 // INlines so that they can be easily compiled out.
180 // Does debug ASSERT checks for functions that require BeginFrame.
181 // Also verifies that we are on the right thread.
182 void checkBeginFrameScope(const char* functionName)
183 {
184 OVR_UNUSED1(functionName); // for Release build.
185 OVR_ASSERT_LOG(BeginFrameCalled == true,
186 ("%s called outside ovrHmd_BeginFrame.", functionName));
187 OVR_DEBUG_LOG_COND(BeginFrameThreadId != OVR::GetCurrentThreadId(),
188 ("%s called on a different thread then ovrHmd_BeginFrame.", functionName));
189 }
191 void checkRenderingConfigured(const char* functionName)
192 {
193 OVR_UNUSED1(functionName); // for Release build.
194 OVR_ASSERT_LOG(RenderingConfigured == true,
195 ("%s called without ovrHmd_ConfigureRendering.", functionName));
196 }
198 void checkBeginFrameTimingScope(const char* functionName)
199 {
200 OVR_UNUSED1(functionName); // for Release build.
201 OVR_ASSERT_LOG(BeginFrameTimingCalled == true,
202 ("%s called outside ovrHmd_BeginFrameTiming.", functionName));
203 }
205 // Get properties by name.
206 bool getBoolValue(const char* propertyName, bool defaultVal);
207 bool setBoolValue(const char* propertyName, bool value);
208 int getIntValue(const char* propertyName, int defaultVal);
209 bool setIntValue(const char* propertyName, int value);
210 float getFloatValue(const char* propertyName, float defaultVal);
211 bool setFloatValue(const char* propertyName, float value);
212 unsigned getFloatArray(const char* propertyName, float values[], unsigned arraySize);
213 bool setFloatArray(const char* propertyName, float values[], unsigned arraySize);
214 const char* getString(const char* propertyName, const char* defaultVal);
215 bool setString(const char* propertyName, const char* value);
217 VirtualHmdId GetNetId() { return NetId; }
219 public:
220 Ptr<Profile> pProfile;
221 // Descriptor that gets allocated and returned to the user as ovrHmd.
222 ovrHmdDesc* pHmdDesc;
223 // Window handle passed in AttachWindow.
224 void* pWindow;
226 // Network
227 Service::NetClient* pClient;
228 VirtualHmdId NetId;
229 HMDNetworkInfo NetInfo;
231 // HMDInfo shouldn't change, as its string pointers are passed out.
232 HMDInfo OurHMDInfo;
234 const char* pLastError;
236 // Caps enabled for the HMD.
237 unsigned EnabledHmdCaps;
239 // Caps actually sent to the Sensor Service
240 unsigned EnabledServiceHmdCaps;
242 // These are the flags actually applied to the Sensor device,
243 // used to track whether SetDisplayReport calls are necessary.
244 //unsigned HmdCapsAppliedToSensor;
246 // *** Sensor
247 Tracking::CombinedSharedStateReader SharedStateReader;
248 Tracking::SensorStateReader TheSensorStateReader;
249 Util::RecordStateReader TheLatencyTestStateReader;
251 bool LatencyTestActive;
252 unsigned char LatencyTestDrawColor[3];
254 bool LatencyTest2Active;
255 unsigned char LatencyTest2DrawColor[3];
257 // Rendering part
258 FrameTimeManager TimeManager;
259 LagStatsCalculator LagStats;
260 LatencyStatisticsCSV LagStatsCSV;
261 HMDRenderState RenderState;
262 Ptr<DistortionRenderer> pRenderer;
264 // Health and Safety Warning display.
265 Ptr<HSWDisplay> pHSWDisplay;
267 // Last timing value reported by BeginFrame.
268 double LastFrameTimeSeconds;
269 // Last timing value reported by GetFrameTime. These are separate since the intended
270 // use is from different threads. TBD: Move to FrameTimeManager? Make atomic?
271 double LastGetFrameTimeSeconds;
273 // Last cached value returned by ovrHmd_GetString/ovrHmd_GetStringArray.
274 char LastGetStringValue[256];
276 // Debug flag set after ovrHmd_ConfigureRendering succeeds.
277 bool RenderingConfigured;
278 // Set after BeginFrame succeeds, and its corresponding thread id for debug checks.
279 bool BeginFrameCalled;
280 ThreadId BeginFrameThreadId;
281 // Graphics functions are not re-entrant from other threads.
282 ThreadChecker RenderAPIThreadChecker;
283 //
284 bool BeginFrameTimingCalled;
285 };
290 //I appreciate this isn't an idea place for this function prototype, but needed
291 //to be seen by OVR_CAPI.cpp and the various SDK renderers of CAPI,
292 //and have everything defined. Please move to a better place if you know of one.
293 ovrBool ovrHmd_CreateDistortionMeshInternal( ovrHmdStruct * hmd,
294 ovrEyeType eyeType, ovrFovPort fov,
295 unsigned int distortionCaps,
296 ovrDistortionMesh *meshData,
297 float overrideEyeReliefIfNonZero=0 );
302 }} // namespace OVR::CAPI
304 #endif // OVR_CAPI_HMDState_h