ovr_sdk

annotate LibOVR/Src/Util/Util_LatencyTest2Reader.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
rev   line source
nuclear@0 1 /************************************************************************************
nuclear@0 2
nuclear@0 3 Filename : Util_LatencyTest2Reader.cpp
nuclear@0 4 Content : Shared functionality for the DK2 latency tester
nuclear@0 5 Created : July 8, 2014
nuclear@0 6 Authors : Volga Aksoy, Chris Taylor
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 "Util_LatencyTest2Reader.h"
nuclear@0 28
nuclear@0 29 namespace OVR { namespace Util {
nuclear@0 30
nuclear@0 31
nuclear@0 32 //// FrameTimeRecord
nuclear@0 33
nuclear@0 34 bool FrameTimeRecord::ColorToReadbackIndex(int *readbackIndex, unsigned char color)
nuclear@0 35 {
nuclear@0 36 int compareColor = color - LT2_ColorIncrement/2;
nuclear@0 37 int index = color / LT2_ColorIncrement; // Use color without subtraction due to rounding.
nuclear@0 38 int delta = compareColor - index * LT2_ColorIncrement;
nuclear@0 39
nuclear@0 40 if ((delta < LT2_PixelTestThreshold) && (delta > -LT2_PixelTestThreshold))
nuclear@0 41 {
nuclear@0 42 *readbackIndex = index;
nuclear@0 43 return true;
nuclear@0 44 }
nuclear@0 45 return false;
nuclear@0 46 }
nuclear@0 47
nuclear@0 48 unsigned char FrameTimeRecord::ReadbackIndexToColor(int readbackIndex)
nuclear@0 49 {
nuclear@0 50 OVR_ASSERT(readbackIndex < LT2_IncrementCount);
nuclear@0 51 return (unsigned char)(readbackIndex * LT2_ColorIncrement + LT2_ColorIncrement/2);
nuclear@0 52 }
nuclear@0 53
nuclear@0 54
nuclear@0 55 //// FrameTimeRecordSet
nuclear@0 56
nuclear@0 57 FrameTimeRecordSet::FrameTimeRecordSet()
nuclear@0 58 {
nuclear@0 59 NextWriteIndex = 0;
nuclear@0 60 memset(this, 0, sizeof(FrameTimeRecordSet));
nuclear@0 61 }
nuclear@0 62
nuclear@0 63 void FrameTimeRecordSet::AddValue(int readValue, double timeSeconds)
nuclear@0 64 {
nuclear@0 65 Records[NextWriteIndex].ReadbackIndex = readValue;
nuclear@0 66 Records[NextWriteIndex].TimeSeconds = timeSeconds;
nuclear@0 67 NextWriteIndex++;
nuclear@0 68 if (NextWriteIndex == RecordCount)
nuclear@0 69 NextWriteIndex = 0;
nuclear@0 70 }
nuclear@0 71 // Matching should be done starting from NextWrite index
nuclear@0 72 // until wrap-around
nuclear@0 73
nuclear@0 74 const FrameTimeRecord& FrameTimeRecordSet::operator [] (int i) const
nuclear@0 75 {
nuclear@0 76 return Records[(NextWriteIndex + i) & RecordMask];
nuclear@0 77 }
nuclear@0 78
nuclear@0 79 const FrameTimeRecord& FrameTimeRecordSet::GetMostRecentFrame()
nuclear@0 80 {
nuclear@0 81 return Records[(NextWriteIndex - 1) & RecordMask];
nuclear@0 82 }
nuclear@0 83
nuclear@0 84 // Advances I to absolute color index
nuclear@0 85 bool FrameTimeRecordSet::FindReadbackIndex(int* i, int readbackIndex) const
nuclear@0 86 {
nuclear@0 87 for (; *i < RecordCount; (*i)++)
nuclear@0 88 {
nuclear@0 89 if ((*this)[*i].ReadbackIndex == readbackIndex)
nuclear@0 90 return true;
nuclear@0 91 }
nuclear@0 92 return false;
nuclear@0 93 }
nuclear@0 94
nuclear@0 95 bool FrameTimeRecordSet::IsAllZeroes() const
nuclear@0 96 {
nuclear@0 97 for (int i = 0; i < RecordCount; i++)
nuclear@0 98 if (Records[i].ReadbackIndex != 0)
nuclear@0 99 return false;
nuclear@0 100 return true;
nuclear@0 101 }
nuclear@0 102
nuclear@0 103
nuclear@0 104 //// RecordStateReader
nuclear@0 105
nuclear@0 106 void RecordStateReader::GetRecordSet(FrameTimeRecordSet& recordset)
nuclear@0 107 {
nuclear@0 108 if(!Updater)
nuclear@0 109 {
nuclear@0 110 return;
nuclear@0 111 }
nuclear@0 112
nuclear@0 113 recordset = Updater->SharedLatencyTestState.GetState();
nuclear@0 114 return;
nuclear@0 115 }
nuclear@0 116
nuclear@0 117
nuclear@0 118 }} // namespace OVR::Util