ovr_sdk

diff LibOVR/Src/CAPI/CAPI_HMDState.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/CAPI/CAPI_HMDState.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,304 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +Filename    :   CAPI_HMDState.h
     1.7 +Content     :   State associated with a single HMD
     1.8 +Created     :   January 24, 2014
     1.9 +Authors     :   Michael Antonov
    1.10 +
    1.11 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.12 +
    1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.15 +which is provided at the time of installation or download, or which 
    1.16 +otherwise accompanies this software in either electronic or hard copy form.
    1.17 +
    1.18 +You may obtain a copy of the License at
    1.19 +
    1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.21 +
    1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.23 +distributed under the License is distributed on an "AS IS" BASIS,
    1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.25 +See the License for the specific language governing permissions and
    1.26 +limitations under the License.
    1.27 +
    1.28 +************************************************************************************/
    1.29 +
    1.30 +#ifndef OVR_CAPI_HMDState_h
    1.31 +#define OVR_CAPI_HMDState_h
    1.32 +
    1.33 +#include "../Kernel/OVR_Math.h"
    1.34 +#include "../Kernel/OVR_List.h"
    1.35 +#include "../Kernel/OVR_Log.h"
    1.36 +#include "../OVR_CAPI.h"
    1.37 +
    1.38 +#include "CAPI_FrameTimeManager.h"
    1.39 +#include "CAPI_LatencyStatistics.h"
    1.40 +#include "CAPI_HMDRenderState.h"
    1.41 +#include "CAPI_DistortionRenderer.h"
    1.42 +#include "CAPI_HSWDisplay.h"
    1.43 +
    1.44 +#include "../Service/Service_NetClient.h"
    1.45 +#include "../Net/OVR_NetworkTypes.h"
    1.46 +#include "../Util/Util_LatencyTest2Reader.h"
    1.47 +
    1.48 +struct ovrHmdStruct { };
    1.49 +
    1.50 +namespace OVR { namespace CAPI {
    1.51 +
    1.52 +
    1.53 +using namespace OVR::Util::Render;
    1.54 +using namespace OVR::Service;
    1.55 +using namespace OVR::Net;
    1.56 +
    1.57 +
    1.58 +//-------------------------------------------------------------------------------------
    1.59 +// ***** ThreadChecker
    1.60 +
    1.61 +// This helper class is used to verify that the API is used according to supported
    1.62 +// thread safety constraints (is not re-entrant for this and related functions).
    1.63 +class ThreadChecker
    1.64 +{
    1.65 +public:
    1.66 +
    1.67 +#ifndef OVR_BUILD_DEBUG
    1.68 +
    1.69 +    // In release build, thread checks are disabled.
    1.70 +    ThreadChecker() { }
    1.71 +    void Begin(const char* functionName)    { OVR_UNUSED1(functionName); }
    1.72 +    void End()                              {  }
    1.73 +
    1.74 +    // Add thread-re-entrancy check for function scope
    1.75 +    struct Scope
    1.76 +    {
    1.77 +        Scope(ThreadChecker*, const char *) { }
    1.78 +        ~Scope() { }
    1.79 +    };
    1.80 +
    1.81 +
    1.82 +#else // OVR_BUILD_DEBUG
    1.83 +    ThreadChecker() : pFunctionName(0), FirstThread(0)
    1.84 +    { }
    1.85 +
    1.86 +    void Begin(const char* functionName)
    1.87 +    {        
    1.88 +        if (!pFunctionName)
    1.89 +        {
    1.90 +            pFunctionName = functionName;
    1.91 +            FirstThread   = GetCurrentThreadId();
    1.92 +        }
    1.93 +        else
    1.94 +        {
    1.95 +            // pFunctionName may be not null here if function is called internally on the same thread.
    1.96 +            OVR_ASSERT_LOG((FirstThread == GetCurrentThreadId()),
    1.97 +                ("%s (threadId=%p) called at the same times as %s (threadId=%p)\n",
    1.98 +                functionName, GetCurrentThreadId(), pFunctionName, FirstThread) );
    1.99 +        }        
   1.100 +    }
   1.101 +    void End()
   1.102 +    {
   1.103 +        pFunctionName = 0;
   1.104 +        FirstThread   = 0;
   1.105 +    }
   1.106 +
   1.107 +    // Add thread-reentrancy check for function scope.
   1.108 +    struct Scope
   1.109 +    {
   1.110 +        Scope(ThreadChecker* threadChecker, const char *functionName) : pChecker(threadChecker)
   1.111 +        { pChecker->Begin(functionName); }
   1.112 +        ~Scope()
   1.113 +        { pChecker->End(); }
   1.114 +    private:
   1.115 +        ThreadChecker* pChecker;
   1.116 +    };
   1.117 +
   1.118 +private:
   1.119 +    // If not 0, contains the name of the function that first entered the scope.
   1.120 +    const char * pFunctionName;
   1.121 +    ThreadId     FirstThread;
   1.122 +
   1.123 +#endif // OVR_BUILD_DEBUG
   1.124 +};
   1.125 +
   1.126 +
   1.127 +//-------------------------------------------------------------------------------------
   1.128 +// ***** HMDState
   1.129 +
   1.130 +// Describes a single HMD.
   1.131 +class HMDState : public ListNode<HMDState>,
   1.132 +                 public ovrHmdStruct, public NewOverrideBase 
   1.133 +{
   1.134 +    void operator=(const HMDState&) { } // Quiet warning.
   1.135 +
   1.136 +protected:   
   1.137 +	HMDState(const OVR::Service::HMDNetworkInfo& netInfo,
   1.138 +			 const OVR::HMDInfo& hmdInfo,
   1.139 +			 Profile* profile,
   1.140 +			 Service::NetClient* client);
   1.141 +    HMDState(const HMDInfo& src, Profile* profile);
   1.142 +
   1.143 +public:   
   1.144 +    virtual ~HMDState();
   1.145 +
   1.146 +    static HMDState* CreateHMDState(Service::NetClient* client, const HMDNetworkInfo& netInfo);
   1.147 +    static HMDState* CreateHMDState(ovrHmdType hmdType); // Used for debug mode
   1.148 +    static const OVR::List<HMDState>& GetHMDStateList();
   1.149 +
   1.150 +    // *** Sensor Setup
   1.151 +
   1.152 +    bool            ConfigureTracking(unsigned supportedCaps, unsigned requiredCaps);    
   1.153 +    void            ResetTracking();
   1.154 +	void			RecenterPose();
   1.155 +    ovrTrackingState PredictedTrackingState(double absTime);
   1.156 +
   1.157 +    // Changes HMD Caps.
   1.158 +    // Capability bits that are not directly or logically tied to one system (such as sensor)
   1.159 +    // are grouped here. ovrHmdCap_VSync, for example, affects rendering and timing.
   1.160 +    void            SetEnabledHmdCaps(unsigned caps);
   1.161 +    unsigned        SetEnabledHmdCaps();
   1.162 +
   1.163 +    bool            ProcessLatencyTest(unsigned char rgbColorOut[3]);
   1.164 +
   1.165 +    // *** Rendering Setup
   1.166 +    bool        ConfigureRendering(ovrEyeRenderDesc eyeRenderDescOut[2],
   1.167 +                                   const ovrFovPort eyeFovIn[2],
   1.168 +                                   const ovrRenderAPIConfig* apiConfig,                                  
   1.169 +                                   unsigned distortionCaps);  
   1.170 +    
   1.171 +    void        UpdateRenderProfile(Profile* profile);
   1.172 +
   1.173 +
   1.174 +    void        SubmitEyeTextures(const ovrPosef renderPose[2],
   1.175 +                                  const ovrTexture eyeTexture[2]);
   1.176 +
   1.177 +
   1.178 +    void sharedInit ( Profile *profile );
   1.179 +
   1.180 +    void applyProfileToSensorFusion();
   1.181 +
   1.182 +    // INlines so that they can be easily compiled out.    
   1.183 +    // Does debug ASSERT checks for functions that require BeginFrame.
   1.184 +    // Also verifies that we are on the right thread.
   1.185 +    void checkBeginFrameScope(const char* functionName)
   1.186 +    {
   1.187 +        OVR_UNUSED1(functionName); // for Release build.
   1.188 +        OVR_ASSERT_LOG(BeginFrameCalled == true,
   1.189 +                       ("%s called outside ovrHmd_BeginFrame.", functionName));
   1.190 +		OVR_DEBUG_LOG_COND(BeginFrameThreadId != OVR::GetCurrentThreadId(),
   1.191 +                       ("%s called on a different thread then ovrHmd_BeginFrame.", functionName));
   1.192 +    }
   1.193 +
   1.194 +    void checkRenderingConfigured(const char* functionName)
   1.195 +    {
   1.196 +        OVR_UNUSED1(functionName); // for Release build.
   1.197 +        OVR_ASSERT_LOG(RenderingConfigured == true,
   1.198 +                       ("%s called without ovrHmd_ConfigureRendering.", functionName));
   1.199 +    }
   1.200 +
   1.201 +    void checkBeginFrameTimingScope(const char* functionName)
   1.202 +    {
   1.203 +        OVR_UNUSED1(functionName); // for Release build.
   1.204 +        OVR_ASSERT_LOG(BeginFrameTimingCalled == true,
   1.205 +                       ("%s called outside ovrHmd_BeginFrameTiming.", functionName));
   1.206 +    }
   1.207 +
   1.208 +	// Get properties by name.
   1.209 +    bool     getBoolValue(const char* propertyName, bool defaultVal);
   1.210 +    bool     setBoolValue(const char* propertyName, bool value);
   1.211 +    int      getIntValue(const char* propertyName, int defaultVal);
   1.212 +    bool     setIntValue(const char* propertyName, int value);
   1.213 +    float    getFloatValue(const char* propertyName, float defaultVal);
   1.214 +    bool     setFloatValue(const char* propertyName, float value);
   1.215 +	unsigned getFloatArray(const char* propertyName, float values[], unsigned arraySize);
   1.216 +    bool     setFloatArray(const char* propertyName, float values[], unsigned arraySize);
   1.217 +    const char* getString(const char* propertyName, const char* defaultVal);
   1.218 +    bool        setString(const char* propertyName, const char* value);
   1.219 +
   1.220 +	VirtualHmdId GetNetId() { return NetId; }
   1.221 +
   1.222 +public:
   1.223 +	Ptr<Profile>            pProfile;
   1.224 +    // Descriptor that gets allocated and returned to the user as ovrHmd.
   1.225 +    ovrHmdDesc*             pHmdDesc;
   1.226 +    // Window handle passed in AttachWindow.
   1.227 +    void*                   pWindow;
   1.228 +
   1.229 +	// Network
   1.230 +	Service::NetClient*     pClient;
   1.231 +	VirtualHmdId            NetId;
   1.232 +	HMDNetworkInfo          NetInfo;
   1.233 +
   1.234 +    // HMDInfo shouldn't change, as its string pointers are passed out.    
   1.235 +    HMDInfo                 OurHMDInfo;
   1.236 +
   1.237 +    const char*             pLastError;
   1.238 +
   1.239 +    // Caps enabled for the HMD.
   1.240 +    unsigned                EnabledHmdCaps;
   1.241 +    
   1.242 +    // Caps actually sent to the Sensor Service
   1.243 +    unsigned                EnabledServiceHmdCaps;
   1.244 +    
   1.245 +    // These are the flags actually applied to the Sensor device,
   1.246 +    // used to track whether SetDisplayReport calls are necessary.
   1.247 +    //unsigned                HmdCapsAppliedToSensor;
   1.248 +    
   1.249 +    // *** Sensor
   1.250 +    Tracking::CombinedSharedStateReader SharedStateReader;
   1.251 +    Tracking::SensorStateReader         TheSensorStateReader;
   1.252 +    Util::RecordStateReader             TheLatencyTestStateReader;
   1.253 +
   1.254 +    bool                    LatencyTestActive;
   1.255 +    unsigned char           LatencyTestDrawColor[3];
   1.256 +
   1.257 +    bool                    LatencyTest2Active;
   1.258 +    unsigned char           LatencyTest2DrawColor[3];
   1.259 +
   1.260 +    // Rendering part
   1.261 +    FrameTimeManager        TimeManager;
   1.262 +    LagStatsCalculator      LagStats;
   1.263 +    LatencyStatisticsCSV    LagStatsCSV;
   1.264 +    HMDRenderState          RenderState;
   1.265 +    Ptr<DistortionRenderer> pRenderer;
   1.266 +
   1.267 +    // Health and Safety Warning display.
   1.268 +    Ptr<HSWDisplay>         pHSWDisplay;
   1.269 +
   1.270 +    // Last timing value reported by BeginFrame.
   1.271 +    double                  LastFrameTimeSeconds;    
   1.272 +    // Last timing value reported by GetFrameTime. These are separate since the intended
   1.273 +    // use is from different threads. TBD: Move to FrameTimeManager? Make atomic?
   1.274 +    double                  LastGetFrameTimeSeconds;
   1.275 +
   1.276 +    // Last cached value returned by ovrHmd_GetString/ovrHmd_GetStringArray.
   1.277 +    char                    LastGetStringValue[256];
   1.278 +   
   1.279 +    // Debug flag set after ovrHmd_ConfigureRendering succeeds.
   1.280 +    bool                    RenderingConfigured;
   1.281 +    // Set after BeginFrame succeeds, and its corresponding thread id for debug checks.
   1.282 +    bool                    BeginFrameCalled;
   1.283 +    ThreadId                BeginFrameThreadId;    
   1.284 +    // Graphics functions are not re-entrant from other threads.
   1.285 +    ThreadChecker           RenderAPIThreadChecker;
   1.286 +    // 
   1.287 +    bool                    BeginFrameTimingCalled;
   1.288 +};
   1.289 +
   1.290 +
   1.291 +
   1.292 +
   1.293 +//I appreciate this isn't an idea place for this function prototype, but needed
   1.294 +//to be seen by OVR_CAPI.cpp and the various SDK renderers of CAPI,
   1.295 +//and have everything defined.  Please move to a better place if you know of one.
   1.296 +ovrBool ovrHmd_CreateDistortionMeshInternal( ovrHmdStruct *  hmd,
   1.297 +                                             ovrEyeType eyeType, ovrFovPort fov,
   1.298 +                                             unsigned int distortionCaps,
   1.299 +                                             ovrDistortionMesh *meshData,
   1.300 +											 float overrideEyeReliefIfNonZero=0 );
   1.301 +
   1.302 +
   1.303 +
   1.304 +
   1.305 +}} // namespace OVR::CAPI
   1.306 +
   1.307 +#endif // OVR_CAPI_HMDState_h