summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/src/timer.cpp
diff options
context:
space:
mode:
author Branimir Karadžić <branimirkaradzic@gmail.com>2017-03-29 17:09:40 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2017-03-29 17:09:40 +0200
commit49f7c99c7786ce257fae28dfeae2f8ee5810424c (patch)
tree1bbd30dd4dd48596186846c2fc77a8dc748215d2 /3rdparty/bx/src/timer.cpp
parent79f22e060b2c012d628d5d1d83288c1bb6e6acef (diff)
Update BGFX and BX (nw)
Diffstat (limited to '3rdparty/bx/src/timer.cpp')
-rw-r--r--3rdparty/bx/src/timer.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/3rdparty/bx/src/timer.cpp b/3rdparty/bx/src/timer.cpp
new file mode 100644
index 00000000000..7f5403749d9
--- /dev/null
+++ b/3rdparty/bx/src/timer.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include <bx/timer.h>
+
+#if BX_PLATFORM_ANDROID
+# include <time.h> // clock, clock_gettime
+#elif BX_PLATFORM_EMSCRIPTEN
+# include <emscripten.h>
+#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT
+# include <windows.h>
+#else
+# include <sys/time.h> // gettimeofday
+#endif // BX_PLATFORM_
+
+namespace bx
+{
+ int64_t getHPCounter()
+ {
+#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT
+ LARGE_INTEGER li;
+ // Performance counter value may unexpectedly leap forward
+ // http://support.microsoft.com/kb/274323
+ QueryPerformanceCounter(&li);
+ int64_t i64 = li.QuadPart;
+#elif BX_PLATFORM_ANDROID
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ int64_t i64 = now.tv_sec*INT64_C(1000000000) + now.tv_nsec;
+#elif BX_PLATFORM_EMSCRIPTEN
+ int64_t i64 = int64_t(1000.0f * emscripten_get_now() );
+#elif !BX_PLATFORM_NONE
+ struct timeval now;
+ gettimeofday(&now, 0);
+ int64_t i64 = now.tv_sec*INT64_C(1000000) + now.tv_usec;
+#else
+ BX_CHECK(false, "Not implemented!");
+ int64_t i64 = UINT64_MAX;
+#endif // BX_PLATFORM_
+ return i64;
+ }
+
+ int64_t getHPFrequency()
+ {
+#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT
+ LARGE_INTEGER li;
+ QueryPerformanceFrequency(&li);
+ return li.QuadPart;
+#elif BX_PLATFORM_ANDROID
+ return INT64_C(1000000000);
+#elif BX_PLATFORM_EMSCRIPTEN
+ return INT64_C(1000000);
+#else
+ return INT64_C(1000000);
+#endif // BX_PLATFORM_
+ }
+
+} // namespace bx