ovr_sdk

annotate LibOVR/Src/CAPI/CAPI_DistortionRenderer.cpp @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
rev   line source
nuclear@0 1 /************************************************************************************
nuclear@0 2
nuclear@0 3 Filename : CAPI_DistortionRenderer.cpp
nuclear@0 4 Content : Combines all of the rendering state associated with the HMD
nuclear@0 5 Created : February 2, 2014
nuclear@0 6 Authors : Michael Antonov
nuclear@0 7
nuclear@0 8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
nuclear@0 9
nuclear@0 10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
nuclear@0 11 you may not use the Oculus VR Rift SDK except in compliance with the License,
nuclear@0 12 which is provided at the time of installation or download, or which
nuclear@0 13 otherwise accompanies this software in either electronic or hard copy form.
nuclear@0 14
nuclear@0 15 You may obtain a copy of the License at
nuclear@0 16
nuclear@0 17 http://www.oculusvr.com/licenses/LICENSE-3.2
nuclear@0 18
nuclear@0 19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
nuclear@0 20 distributed under the License is distributed on an "AS IS" BASIS,
nuclear@0 21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nuclear@0 22 See the License for the specific language governing permissions and
nuclear@0 23 limitations under the License.
nuclear@0 24
nuclear@0 25 ************************************************************************************/
nuclear@0 26
nuclear@0 27 #include "CAPI_DistortionRenderer.h"
nuclear@0 28
nuclear@0 29 #if defined (OVR_OS_WIN32)
nuclear@0 30
nuclear@0 31 // TBD: Move to separate config file that handles back-ends.
nuclear@0 32 #define OVR_D3D_VERSION 11
nuclear@0 33 #include "D3D1X/CAPI_D3D1X_DistortionRenderer.h"
nuclear@0 34 #undef OVR_D3D_VERSION
nuclear@0 35
nuclear@0 36 #define OVR_D3D_VERSION 10
nuclear@0 37 #include "D3D1X/CAPI_D3D1X_DistortionRenderer.h"
nuclear@0 38 #undef OVR_D3D_VERSION
nuclear@0 39
nuclear@0 40 #define OVR_D3D_VERSION 9
nuclear@0 41 #include "D3D9/CAPI_D3D9_DistortionRenderer.h"
nuclear@0 42 #undef OVR_D3D_VERSION
nuclear@0 43
nuclear@0 44 #endif
nuclear@0 45
nuclear@0 46 #include "GL/CAPI_GL_DistortionRenderer.h"
nuclear@0 47
nuclear@0 48 namespace OVR { namespace CAPI {
nuclear@0 49
nuclear@0 50 //-------------------------------------------------------------------------------------
nuclear@0 51 // ***** DistortionRenderer
nuclear@0 52
nuclear@0 53 // TBD: Move to separate config file that handles back-ends.
nuclear@0 54
nuclear@0 55 DistortionRenderer::CreateFunc DistortionRenderer::APICreateRegistry[ovrRenderAPI_Count] =
nuclear@0 56 {
nuclear@0 57 0, // None
nuclear@0 58 &GL::DistortionRenderer::Create,
nuclear@0 59 0, // Android_GLES
nuclear@0 60 #if defined (OVR_OS_WIN32)
nuclear@0 61 &D3D9::DistortionRenderer::Create,
nuclear@0 62 &D3D10::DistortionRenderer::Create,
nuclear@0 63 &D3D11::DistortionRenderer::Create
nuclear@0 64 #else
nuclear@0 65 0,
nuclear@0 66 0,
nuclear@0 67 0
nuclear@0 68 #endif
nuclear@0 69 };
nuclear@0 70
nuclear@0 71 void DistortionRenderer::SetLatencyTestColor(unsigned char* color)
nuclear@0 72 {
nuclear@0 73 if(color)
nuclear@0 74 {
nuclear@0 75 LatencyTestDrawColor[0] = color[0];
nuclear@0 76 LatencyTestDrawColor[1] = color[1];
nuclear@0 77 LatencyTestDrawColor[2] = color[2];
nuclear@0 78 }
nuclear@0 79
nuclear@0 80 LatencyTestActive = color != NULL;
nuclear@0 81 }
nuclear@0 82
nuclear@0 83 void DistortionRenderer::SetLatencyTest2Color(unsigned char* color)
nuclear@0 84 {
nuclear@0 85 if(color)
nuclear@0 86 {
nuclear@0 87 LatencyTest2DrawColor[0] = color[0];
nuclear@0 88 LatencyTest2DrawColor[1] = color[1];
nuclear@0 89 LatencyTest2DrawColor[2] = color[2];
nuclear@0 90 }
nuclear@0 91
nuclear@0 92 LatencyTest2Active = color != NULL;
nuclear@0 93 }
nuclear@0 94
nuclear@0 95 void DistortionRenderer::GetOverdriveScales(float& outRiseScale, float& outFallScale)
nuclear@0 96 {
nuclear@0 97 outRiseScale = 0.1f;
nuclear@0 98 outFallScale = 0.05f; // falling issues are hardly visible
nuclear@0 99 }
nuclear@0 100
nuclear@0 101 double DistortionRenderer::WaitTillTime(double absTime)
nuclear@0 102 {
nuclear@0 103 double initialTime = ovr_GetTimeInSeconds();
nuclear@0 104 if (initialTime >= absTime)
nuclear@0 105 return 0.0;
nuclear@0 106
nuclear@0 107 double newTime = initialTime;
nuclear@0 108
nuclear@0 109 while (newTime < absTime)
nuclear@0 110 {
nuclear@0 111 // TODO: Needs further testing before enabling it on all Windows configs
nuclear@0 112 #if 0 //def OVR_OS_WIN32
nuclear@0 113 double remainingWaitTime = absTime - newTime;
nuclear@0 114
nuclear@0 115 // don't yield if <2ms
nuclear@0 116 if(remainingWaitTime > 0.002)
nuclear@0 117 {
nuclear@0 118 // round down wait time to closest 1 ms
nuclear@0 119 int roundedWaitTime = (remainingWaitTime * 1000);
nuclear@0 120
nuclear@0 121 waitableTimerInterval.QuadPart = -10000LL; // 10000 * 100 ns = 1 ms
nuclear@0 122 waitableTimerInterval.QuadPart *= roundedWaitTime;
nuclear@0 123
nuclear@0 124 SetWaitableTimer(timer, &waitableTimerInterval, 0, NULL, NULL, TRUE);
nuclear@0 125 DWORD waitResult = WaitForSingleObject(timer, roundedWaitTime + 3); // give 3 ms extra time
nuclear@0 126 OVR_UNUSED(waitResult);
nuclear@0 127
nuclear@0 128 #ifdef OVR_BUILD_DEBUG
nuclear@0 129 double sleptTime = ovr_GetTimeInSeconds() - newTime;
nuclear@0 130 // Make sure we didn't sleep too long and it is reliable, otherwise we might miss v-sync causing a stutter
nuclear@0 131 if (sleptTime > (roundedWaitTime + 2) * 0.001)
nuclear@0 132 {
nuclear@0 133 OVR_DEBUG_LOG_TEXT(
nuclear@0 134 ("[DistortionRenderer::WaitTillTime] Sleep interval too long: %f\n", sleptTime));
nuclear@0 135 }
nuclear@0 136 else
nuclear@0 137 {
nuclear@0 138 OVR_ASSERT(WAIT_OBJECT_0 == waitResult);
nuclear@0 139 }
nuclear@0 140 #endif
nuclear@0 141 }
nuclear@0 142 else
nuclear@0 143 #endif
nuclear@0 144 {
nuclear@0 145 for (int j = 0; j < 5; j++)
nuclear@0 146 OVR_PROCESSOR_PAUSE();
nuclear@0 147 }
nuclear@0 148
nuclear@0 149 newTime = ovr_GetTimeInSeconds();
nuclear@0 150 }
nuclear@0 151
nuclear@0 152 // How long we waited
nuclear@0 153 return newTime - initialTime;
nuclear@0 154 }
nuclear@0 155
nuclear@0 156 }} // namespace OVR::CAPI
nuclear@0 157