ovr_sdk
diff LibOVR/Src/Util/Util_LatencyTest2Reader.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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/Util/Util_LatencyTest2Reader.cpp Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,118 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +Filename : Util_LatencyTest2Reader.cpp 1.7 +Content : Shared functionality for the DK2 latency tester 1.8 +Created : July 8, 2014 1.9 +Authors : Volga Aksoy, Chris Taylor 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 +#include "Util_LatencyTest2Reader.h" 1.31 + 1.32 +namespace OVR { namespace Util { 1.33 + 1.34 + 1.35 +//// FrameTimeRecord 1.36 + 1.37 +bool FrameTimeRecord::ColorToReadbackIndex(int *readbackIndex, unsigned char color) 1.38 +{ 1.39 + int compareColor = color - LT2_ColorIncrement/2; 1.40 + int index = color / LT2_ColorIncrement; // Use color without subtraction due to rounding. 1.41 + int delta = compareColor - index * LT2_ColorIncrement; 1.42 + 1.43 + if ((delta < LT2_PixelTestThreshold) && (delta > -LT2_PixelTestThreshold)) 1.44 + { 1.45 + *readbackIndex = index; 1.46 + return true; 1.47 + } 1.48 + return false; 1.49 +} 1.50 + 1.51 +unsigned char FrameTimeRecord::ReadbackIndexToColor(int readbackIndex) 1.52 +{ 1.53 + OVR_ASSERT(readbackIndex < LT2_IncrementCount); 1.54 + return (unsigned char)(readbackIndex * LT2_ColorIncrement + LT2_ColorIncrement/2); 1.55 +} 1.56 + 1.57 + 1.58 +//// FrameTimeRecordSet 1.59 + 1.60 +FrameTimeRecordSet::FrameTimeRecordSet() 1.61 +{ 1.62 + NextWriteIndex = 0; 1.63 + memset(this, 0, sizeof(FrameTimeRecordSet)); 1.64 +} 1.65 + 1.66 +void FrameTimeRecordSet::AddValue(int readValue, double timeSeconds) 1.67 +{ 1.68 + Records[NextWriteIndex].ReadbackIndex = readValue; 1.69 + Records[NextWriteIndex].TimeSeconds = timeSeconds; 1.70 + NextWriteIndex++; 1.71 + if (NextWriteIndex == RecordCount) 1.72 + NextWriteIndex = 0; 1.73 +} 1.74 +// Matching should be done starting from NextWrite index 1.75 +// until wrap-around 1.76 + 1.77 +const FrameTimeRecord& FrameTimeRecordSet::operator [] (int i) const 1.78 +{ 1.79 + return Records[(NextWriteIndex + i) & RecordMask]; 1.80 +} 1.81 + 1.82 +const FrameTimeRecord& FrameTimeRecordSet::GetMostRecentFrame() 1.83 +{ 1.84 + return Records[(NextWriteIndex - 1) & RecordMask]; 1.85 +} 1.86 + 1.87 +// Advances I to absolute color index 1.88 +bool FrameTimeRecordSet::FindReadbackIndex(int* i, int readbackIndex) const 1.89 +{ 1.90 + for (; *i < RecordCount; (*i)++) 1.91 + { 1.92 + if ((*this)[*i].ReadbackIndex == readbackIndex) 1.93 + return true; 1.94 + } 1.95 + return false; 1.96 +} 1.97 + 1.98 +bool FrameTimeRecordSet::IsAllZeroes() const 1.99 +{ 1.100 + for (int i = 0; i < RecordCount; i++) 1.101 + if (Records[i].ReadbackIndex != 0) 1.102 + return false; 1.103 + return true; 1.104 +} 1.105 + 1.106 + 1.107 +//// RecordStateReader 1.108 + 1.109 +void RecordStateReader::GetRecordSet(FrameTimeRecordSet& recordset) 1.110 +{ 1.111 + if(!Updater) 1.112 + { 1.113 + return; 1.114 + } 1.115 + 1.116 + recordset = Updater->SharedLatencyTestState.GetState(); 1.117 + return; 1.118 +} 1.119 + 1.120 + 1.121 +}} // namespace OVR::Util