OpenGL ES SDK for Android
ARM Developer Center
Home
Pages
Namespaces
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Utils.h
Go to the documentation of this file.
1
/* Copyright (c) 2017, ARM Limited and Contributors
2
*
3
* SPDX-License-Identifier: MIT
4
*
5
* Permission is hereby granted, free of charge,
6
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation the rights to
8
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
*
13
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
*/
20
21
#pragma once
22
#include <time.h>
23
24
namespace
Stats
25
{
26
timespec
endFrame
;
27
timespec
startFrame
;
28
uint32_t
nbFrame
= 0;
29
uint32_t
totalNbFrame
;
30
double
TotalFrameTime
= 0;
31
32
inline
void
StartFrame
()
33
{
34
startFrame
=
endFrame
;
35
}
36
37
inline
void
EndFrame
()
38
{
39
clock_gettime(CLOCK_REALTIME, &
endFrame
);
40
float
diff = (
endFrame
.tv_sec -
startFrame
.tv_sec) + (
endFrame
.tv_nsec -
startFrame
.tv_nsec);
41
if
(diff < 0)
42
diff += 1000000000;
43
44
TotalFrameTime
+= diff;
45
++
nbFrame
;
46
++
totalNbFrame
;
47
}
48
49
inline
float
GetFPS
()
50
{
51
return
1000000000 / (
TotalFrameTime
/
nbFrame
);
52
}
53
54
inline
float
GetAverageFrameTime
()
55
{
56
return
(
TotalFrameTime
/
nbFrame
) / 1000000;
57
}
58
59
inline
void
Clear
()
60
{
61
TotalFrameTime
= 0;
62
nbFrame
= 0;
63
}
64
65
}
Stats::nbFrame
uint32_t nbFrame
Definition:
Utils.h:28
Stats::StartFrame
void StartFrame()
Definition:
Utils.h:32
Stats::endFrame
timespec endFrame
Definition:
Utils.h:26
Stats::TotalFrameTime
double TotalFrameTime
Definition:
Utils.h:30
Stats::startFrame
timespec startFrame
Definition:
Utils.h:27
Stats::GetAverageFrameTime
float GetAverageFrameTime()
Definition:
Utils.h:54
Stats::Clear
void Clear()
Definition:
Utils.h:59
Stats::GetFPS
float GetFPS()
Definition:
Utils.h:49
Stats::EndFrame
void EndFrame()
Definition:
Utils.h:37
Stats::totalNbFrame
uint32_t totalNbFrame
Definition:
Utils.h:29
samples
tutorials
FoveatedRendering
jni
Utils.h
(C) ARM Ltd. 2017