summaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/CAPI/CAPI_DistortionRenderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'LibOVR/Src/CAPI/CAPI_DistortionRenderer.cpp')
-rw-r--r--LibOVR/Src/CAPI/CAPI_DistortionRenderer.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/LibOVR/Src/CAPI/CAPI_DistortionRenderer.cpp b/LibOVR/Src/CAPI/CAPI_DistortionRenderer.cpp
index 613d8fb..217310c 100644
--- a/LibOVR/Src/CAPI/CAPI_DistortionRenderer.cpp
+++ b/LibOVR/Src/CAPI/CAPI_DistortionRenderer.cpp
@@ -68,6 +68,83 @@ DistortionRenderer::CreateFunc DistortionRenderer::APICreateRegistry[ovrRenderAP
#endif
};
+void DistortionRenderer::SetLatencyTestColor(unsigned char* color)
+{
+ if(color)
+ {
+ LatencyTestDrawColor[0] = color[0];
+ LatencyTestDrawColor[1] = color[1];
+ LatencyTestDrawColor[2] = color[2];
+ }
+
+ LatencyTestActive = color != NULL;
+}
+
+void DistortionRenderer::SetLatencyTest2Color(unsigned char* color)
+{
+ if(color)
+ {
+ LatencyTest2DrawColor[0] = color[0];
+ LatencyTest2DrawColor[1] = color[1];
+ LatencyTest2DrawColor[2] = color[2];
+ }
+
+ LatencyTest2Active = color != NULL;
+}
+
+double DistortionRenderer::WaitTillTime(double absTime)
+{
+ double initialTime = ovr_GetTimeInSeconds();
+ if (initialTime >= absTime)
+ return 0.0;
+
+ double newTime = initialTime;
+ volatile int i;
+
+ while (newTime < absTime)
+ {
+// TODO: Needs further testing before enabling it on all Windows configs
+#if 0 //def OVR_OS_WIN32
+ double remainingWaitTime = absTime - newTime;
+
+ // don't yield if <2ms
+ if(remainingWaitTime > 0.002)
+ {
+ // round down wait time to closest 1 ms
+ int roundedWaitTime = (remainingWaitTime * 1000);
+
+ waitableTimerInterval.QuadPart = -10000LL; // 10000 * 100 ns = 1 ms
+ waitableTimerInterval.QuadPart *= roundedWaitTime;
+
+ SetWaitableTimer(timer, &waitableTimerInterval, 0, NULL, NULL, TRUE);
+ DWORD waitResult = WaitForSingleObject(timer, roundedWaitTime + 3); // give 3 ms extra time
+
+ double sleptTime = ovr_GetTimeInSeconds() - newTime;
+ // Make sure this is reliable (should be waiting for 1ms, make sure it's <2ms)
+ if (sleptTime > remainingWaitTime)
+ {
+ OVR_DEBUG_LOG_TEXT(
+ ("[DistortionRenderer::FlushGpuAndWaitTillTime] Sleep interval too long: %f\n", sleptTime));
+ }
+ else
+ {
+ OVR_ASSERT(WAIT_OBJECT_0 == waitResult);
+ OVR_UNUSED(waitResult);
+ }
+ }
+ else
+#endif
+ {
+ for (int j = 0; j < 50; j++)
+ i = 0;
+ }
+
+ newTime = ovr_GetTimeInSeconds();
+ }
+
+ // How long we waited
+ return newTime - initialTime;
+}
}} // namespace OVR::CAPI