ovr_sdk

view LibOVR/Src/CAPI/CAPI_DistortionRenderer.cpp @ 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_DistortionRenderer.cpp
4 Content : Combines all of the rendering state associated with the HMD
5 Created : February 2, 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 #include "CAPI_DistortionRenderer.h"
29 #if defined (OVR_OS_WIN32)
31 // TBD: Move to separate config file that handles back-ends.
32 #define OVR_D3D_VERSION 11
33 #include "D3D1X/CAPI_D3D1X_DistortionRenderer.h"
34 #undef OVR_D3D_VERSION
36 #define OVR_D3D_VERSION 10
37 #include "D3D1X/CAPI_D3D1X_DistortionRenderer.h"
38 #undef OVR_D3D_VERSION
40 #define OVR_D3D_VERSION 9
41 #include "D3D9/CAPI_D3D9_DistortionRenderer.h"
42 #undef OVR_D3D_VERSION
44 #endif
46 #include "GL/CAPI_GL_DistortionRenderer.h"
48 namespace OVR { namespace CAPI {
50 //-------------------------------------------------------------------------------------
51 // ***** DistortionRenderer
53 // TBD: Move to separate config file that handles back-ends.
55 DistortionRenderer::CreateFunc DistortionRenderer::APICreateRegistry[ovrRenderAPI_Count] =
56 {
57 0, // None
58 &GL::DistortionRenderer::Create,
59 0, // Android_GLES
60 #if defined (OVR_OS_WIN32)
61 &D3D9::DistortionRenderer::Create,
62 &D3D10::DistortionRenderer::Create,
63 &D3D11::DistortionRenderer::Create
64 #else
65 0,
66 0,
67 0
68 #endif
69 };
71 void DistortionRenderer::SetLatencyTestColor(unsigned char* color)
72 {
73 if(color)
74 {
75 LatencyTestDrawColor[0] = color[0];
76 LatencyTestDrawColor[1] = color[1];
77 LatencyTestDrawColor[2] = color[2];
78 }
80 LatencyTestActive = color != NULL;
81 }
83 void DistortionRenderer::SetLatencyTest2Color(unsigned char* color)
84 {
85 if(color)
86 {
87 LatencyTest2DrawColor[0] = color[0];
88 LatencyTest2DrawColor[1] = color[1];
89 LatencyTest2DrawColor[2] = color[2];
90 }
92 LatencyTest2Active = color != NULL;
93 }
95 void DistortionRenderer::GetOverdriveScales(float& outRiseScale, float& outFallScale)
96 {
97 outRiseScale = 0.1f;
98 outFallScale = 0.05f; // falling issues are hardly visible
99 }
101 double DistortionRenderer::WaitTillTime(double absTime)
102 {
103 double initialTime = ovr_GetTimeInSeconds();
104 if (initialTime >= absTime)
105 return 0.0;
107 double newTime = initialTime;
109 while (newTime < absTime)
110 {
111 // TODO: Needs further testing before enabling it on all Windows configs
112 #if 0 //def OVR_OS_WIN32
113 double remainingWaitTime = absTime - newTime;
115 // don't yield if <2ms
116 if(remainingWaitTime > 0.002)
117 {
118 // round down wait time to closest 1 ms
119 int roundedWaitTime = (remainingWaitTime * 1000);
121 waitableTimerInterval.QuadPart = -10000LL; // 10000 * 100 ns = 1 ms
122 waitableTimerInterval.QuadPart *= roundedWaitTime;
124 SetWaitableTimer(timer, &waitableTimerInterval, 0, NULL, NULL, TRUE);
125 DWORD waitResult = WaitForSingleObject(timer, roundedWaitTime + 3); // give 3 ms extra time
126 OVR_UNUSED(waitResult);
128 #ifdef OVR_BUILD_DEBUG
129 double sleptTime = ovr_GetTimeInSeconds() - newTime;
130 // Make sure we didn't sleep too long and it is reliable, otherwise we might miss v-sync causing a stutter
131 if (sleptTime > (roundedWaitTime + 2) * 0.001)
132 {
133 OVR_DEBUG_LOG_TEXT(
134 ("[DistortionRenderer::WaitTillTime] Sleep interval too long: %f\n", sleptTime));
135 }
136 else
137 {
138 OVR_ASSERT(WAIT_OBJECT_0 == waitResult);
139 }
140 #endif
141 }
142 else
143 #endif
144 {
145 for (int j = 0; j < 5; j++)
146 OVR_PROCESSOR_PAUSE();
147 }
149 newTime = ovr_GetTimeInSeconds();
150 }
152 // How long we waited
153 return newTime - initialTime;
154 }
156 }} // namespace OVR::CAPI